How does parent process get the termination status through wait from a child process which calls _exit

前端 未结 4 431
滥情空心
滥情空心 2021-01-15 16:31

I have read the following statement.

The status argument given to _exit() defines the termination status of the process, which is available to the p

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-15 16:35

    Inside the _exit(int status) function, the process notifies the parent process via SIGCHLD that that it is about to terminate, and the low-order 8 bits of status are made available to the parent. There are three ways in which the exit status is handled

    1. The parent process may indicate that it's not interested in the return value, and in this case the exit status is discarded, and child process terminates.
    2. The parent process may be in a wait(), then the status is communicated to the parent, and the child process terminates.
    3. The parent process is not in wait(), then the child process turns into a zombie process, whose purpose is to wait for the parent to make a call to wait() to retrieve the exit status.

提交回复
热议问题