Reputation: 6008
A child process can:
exit(0)
,exit(22)
, exit(23)
) -- This is obviously specific to my applicationI am doing a fork/exec from a parent process and looping on waitpid
, when I detect that child process has exited I would like to determine the reason it exited.
Currently I check WEXITSTATUS(status)
(where status
is returned by waitpid
) to determine exit code.
Is there a way to reliably detect if child exited abnormally?
Upvotes: 2
Views: 3857
Reputation: 16781
You can check for WIFSIGNALED(status)
. For testing this check out Test cases in C for WIFSIGNALED, WIFSTOPPED, WIFCONTINUED.
Of course you can also do a positive check for normal termination with WIFEXITED(status)
.
Upvotes: 5