Let's look at the example of a parent process sending a kill signal to a child process:
#include <stdio.h> #include <unistd.h> #include <signal.h> #include <sys/types.h> #include < Sys/wait.h>int Main (int argc, const char *argv[]) { pid_t pid; int status; PID = fork (); if (0 = = pid) { printf ("Hi, I ' m child process!\n"); Sleep (ten); } else if (PID > 0) { printf ("Send signal to Child process (%d) \ n", pid); Sleep (1); Kill (PID, SIGABRT); Wait (&status); if (wifsignaled (status)) { printf ("Child process received Singal%d\n", Wtermsig (status)); } } else { printf ("Fork wrong!\n"); return 1; } return 0;}
Macro that determines the status of the child process exit:
the end state of the child process is returned and stored in status, with several macros at the bottom to determine the end condition
wifexited (status) is a non-0 value if the child process ends normally.
wexitstatus (status) Gets the end code returned by the child process exit (), typically using wifexited to determine whether the macro ends properly before it can be used.
wifsignaled (status) This macro value is true if the child process ends because of a signal
wtermsig (status) Gets the signal code that the child process aborts because of the signal, generally uses wifsignaled to judge before using this macro.
wifstopped (status) This macro value is true if the child process is in a paused execution condition. This is generally the case only if you are using wuntraced.
wstopsig (status) Gets the signal code that caused the child process to pause.
The parent process of Linux to the child process to send a Kill signal example and the status of the child process to judge