/*體現(xiàn)exit和_exit的區(qū)別*/
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
int main(void)
{
pid_t pid;
if ( (pid = fork() )==-1 ) //如果創(chuàng)建子進(jìn)程失敗
{
perror ("創(chuàng)建子進(jìn)程失敗\n"); //創(chuàng)建子進(jìn)程出錯(cuò)信息
exit(0);
}
else if(pid==0) //子進(jìn)程
{
printf("01:這是子進(jìn)程\n");
printf("02:這是子進(jìn)程,目前數(shù)據(jù)在緩沖區(qū)中");
//這個(gè)地方?jīng)]有換行符,所以不寫(xiě)出數(shù)據(jù)
exit(0); //退出,強(qiáng)制清空,會(huì)輸出上面未完成數(shù)據(jù)
}
else //父進(jìn)程
{
sleep(1); //休眠一秒以確定先后順序
printf("03:這是父進(jìn)程,開(kāi)始輸出\n");
printf("04:這是夫進(jìn)程,目前數(shù)據(jù)在緩沖區(qū)中"); //同樣沒(méi)有換行符
_exit(0); //_exit函數(shù)會(huì)直接丟棄相應(yīng)的數(shù)據(jù)
}
return 0;
}
分享名稱(chēng):[Linux進(jìn)程]展示exit和_exit函數(shù)的區(qū)別
當(dāng)前鏈接:http://www.yijiale78.com/article0/pchiio.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供ChatGPT、動(dòng)態(tài)網(wǎng)站、網(wǎng)站收錄、服務(wù)器托管、外貿(mào)建站、網(wǎng)頁(yè)設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)