我在孩子中以-1退出,但父母取而代之。有沒有辦法讓父母識別-1?這裏是我的代碼分叉的孩子以-1退出,但WEXITSTATUS獲得255
pid = fork();
// if fork fails
if (pid < 0){
exit(EXIT_FAILURE);
}
else if (pid == 0){
// purposely exit
_exit(-1);
}
else{
int status;
int corpse = wait(&status);
if (WIFEXITED(status))
{
int estat = WEXITSTATUS(status);
if (estat == 0){
printf("Command was successfully executed\n");
}
else{
printf("Error: child exited with status %d\n", estat);
}
}
else
printf("signalled\n", corpse);
「WEXITSTATUS」中返回變量的類型是什麼? – IllusiveBrian 2014-10-18 02:35:13
無符號十進制整數?我如何將它轉換爲-1? – Mariska 2014-10-18 02:39:19