As mentioned in the previous notes, the parent process can get to its terminating state either through the wait function or the WAITPID function, regardless of whether the child process terminates normally or terminates abnormally. However, the information obtained by the normal termination and the abnormal termination of the parent process is different, and the parent process receives the parameter of exit in the child process at normal termination, and the parent process receives the signal number value that causes the child process to terminate abnormally when the exception terminates. the normal termination of the status value returned to the parent process and the signal value passed to the parent process at the end of the exception is stored on the different bits of the memory that the wait or Waitpid function's parameter status points to. If the parent process wants to know whether the child process is terminating normally or terminating abnormally, it can be determined by determining if there is a value on the corresponding bit. The Linux system provides several macros to implement:
- wifexited (status): Test whether it is a normal exit
- Wexitstatus (status): Gets the terminating status value of the child process
- Wifsignaled (status): Test for abnormal exit
- Wtermsig (status): Gets the signal number value that caused the child process to terminate abnormally
Process Control (eight)---child process-terminated state-related macros