
WIFEXITED/WEXITSTATUS/WIFSIGNALED
2008-06-1315:07
Iftheexitstatusvalue(*noteProgramTermination::)ofthechild
processiszero,thenthestatusvaluereportedby`waitpid'or`wait'
isalsozero.Youcantestforotherkindsofinformationencodedin
thereturnedstatusvalueusingthefollowingmacros.Thesemacrosare
definedintheheaderfile`sys/wait.h'.
--Macro:intWIFEXITED(intSTATUS)
Thismacroreturnsanonzerovalueifthechildprocessterminated
normallywith`exit'or`_exit'.
--Macro:intWEXITSTATUS(intSTATUS)
If`WIFEXITED'istrueofSTATUS,thismacroreturnsthelow-order
8bitsoftheexitstatusvaluefromthechildprocess.*Note
ExitStatus::.
--Macro:intWIFSIGNALED(intSTATUS)
Thismacroreturnsanonzerovalueifthechildprocessterminated
becauseitreceivedasignalthatwasnothandled.*NoteSignal
Handling::.
子進程的結(jié)束狀態(tài)返回后存于status,底下有幾個宏可判別結(jié)束情況
WIFEXITED(status)如果子進程正常結(jié)束則為非0值。
WEXITSTATUS(status)取得子進程exit()返回的結(jié)束代碼,一般會先用WIFEXITED來判斷是否正常結(jié)束才能使用此宏。
WIFSIGNALED(status)如果子進程是因為信號而結(jié)束則此宏值為真
WTERMSIG(status)取得子進程因信號而中止的信號代碼,一般會先用WIFSIGNALED來判斷后才使用此宏。
WIFSTOPPED(status)如果子進程處于暫停執(zhí)行情況則此宏值為真。一般只有使用WUNTRACED時才會有此情況。
WSTOPSIG(status)取得引發(fā)子進程暫停的信號代碼,一般會先用WIFSTOPPED來判斷后才使用此宏。
愛華網(wǎng)



