/* file: print_child_status.c author: Ted Baker last modified: $Author: cop4610 $ on $Date: 2002/09/02 00:23:13 $ purpose: print out reason for process termination */ #define _XOPEN_SOURCE 500 #define _GNU_SOURCE /* allow Gnu extensions, for function strsignal() (a non-standard OS API extension supported by Solaris and Linux) */ #include #include #include void print_child_status (int status) { if (WIFEXITED (status)) { fprintf (stdout, "Child exited with status %d\n", WEXITSTATUS (status)); } else if (WIFSTOPPED (status)) { fprintf (stdout, "Child stopped by signal %d (%s)\n", WSTOPSIG (status), strsignal (WSTOPSIG (status))); } else if (WIFSIGNALED (status)) { fprintf (stdout, "Child killed by signal %d (%s)\n", WTERMSIG (status), strsignal (WTERMSIG (status))); } else { fprintf (stdout, "Unknown child status\n"); } }