Kam
Kam

Reputation: 6008

How to detect that a child process has crashed?

A child process can:

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?

Upvotes: 2

Views: 3857

Answers (1)

Werner Henze
Werner Henze

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

Related Questions