#include#include#include
#include
#include
intmain()
else }
return0;
} 輸出結果如下:
parent process4595 child process4596
i catched a child process with pid of
4596
parent process4595 child process4597
i catched a child process with pid of
4597
parent process4595 child process4598
i catched a child process with pid of
4598
當把exit注釋後輸出結果如下:
parent process4642 child process4643
parent process4643 child process4644
parent process4644 child process4645
i catched a child process with pid of
4645
i catched a child process with pid of
4644
parent process4643 child process4646
i catched a child process with pid of
4646
i catched a child process with pid of
4643
parent process4642 child process4647
parent process4647 child process4648
i catched a child process with pid of
4648
i catched a child process with pid of
4647
parent process4642 child process4649
i catched a child process with pid of
4649
//重新執行一邊的結果
parent process4657 child process4658
parent process4658 child process4659
parent process4659 child process4660
i catched a child process with pid of
4660
i catched a child process with pid of
4659
parent process4658 child process4661
i catched a child process with pid of
4661
i catched a child process with pid of
4658
parent process4657 child process4662
parent process4662 child process4663
i catched a child process with pid of
4663
i catched a child process with pid of
4662
parent process4657 child process4664
i catched a child process with pid of
4664
從上面的輸出結果可以得出:exit可以用來釋放程序的資源,必須加上,當注釋掉時,可能因為子程序的資源沒有
及時清理掉,所以導致wait阻塞住,不能及時清理掉子程序!
總結:當程序發出exit該呼叫時,核心會釋放程序占有的資源,釋放程序上下文所佔的記憶體空間,保留
程序表項,將程序表項中記錄程序狀態的關鍵字設為僵死狀態。核心在程序收到不可撲捉的訊號時,會從核心內部呼叫exit
,使得程序退出。父程序通過wait,並釋放程序表項。
exit和wait一起可以徹底清除子程序的資源
include include include include include intmain else return0 輸出結果如下 parent process4595 child process4596 i catched a child process with pid of 4596 pa...
和Top一起成長
秒殺!09年比較火的乙個詞 從剛開始秒殺手機,電腦,到後來的秒殺汽車,到現在的秒殺房地產 相對於 的秒殺,我有許多事情,進展的比較緩慢,參加 top比賽乙個多月了,一直想寫點什麼,和大家一起享,但是卻拖到了現在 下面我就和大家分享一下我使用 top平台的一些體會和心得.一 見證 的崛起1 全球網際網...
和怎樣的人一起創業
當本刊記者走進創新工場辦公室時,稍顯紛亂的布置表明這是乙個建立不久的公司。但桌子上放置的 世界因你不同 李開復自傳 的書籍好像在闡釋這裡的與眾不同。這就是李開復即將再次起航的地方。巧合的是,樓下的公司指示牌上,這層辦公室還保留著原來google公司的標示,而辦公室的地毯上,取自google圖示中的顏...