A framework something like the below will allow you check the results of the wait()
and waitpid()
calls.
pid_t pid = fork();
if (pid == 0) {
/* child */
sleep(200);
}
else {
/* parent */
kill(pid, SIGSTOP);
/* do wait(), waitpid() stuff */
}
You do not actually have to catch the signals (using signal()
or related function) that are sent. signal()
installs a handler that overrides the default behavior for the specific signal - so if you want to check for a signal terminating your process, pick one that has that default behavior - "man -s7 signal
" will give you details a signal's default behavior.
For the macros you have mentioned use SIGSTOP
for WIFSTOPPED(status)
, SIGCONT
for WIFCONTINUED (status)
and SIGINT
for WIFSIGNALED(status)
If you want more flexibility for testing, you could use kill (see "man kill
") to send signals to your process. kill -l
will list all the signals that can be sent.