2

A child process can:

  • Exit normally (by exiting using exit(0),exit(22), exit(23)) -- This is obviously specific to my application
  • Exit abnormally (code throws an exception, receives an unhandled signal, core dumps, etc...)

I 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?

Jay
  • 9,585
  • 6
  • 49
  • 72
Kam
  • 5,878
  • 10
  • 53
  • 97

1 Answers1

5

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).

Community
  • 1
  • 1
Werner Henze
  • 16,404
  • 12
  • 44
  • 69