exit(...): 会导致父进程终止吗?

exit(...): Will it cause parent process to terminate?

如果我在子进程中调用 exit(1),此操作是否也会导致父进程终止?或者只是只有子进程被 exit(1)?

终止

exit 不会导致父级也退出。它会导致当前进程正常终止。

man exit

这表明

The exit() function causes normal [current/child] process termination and the value of [the exit] status is returned to the parent [process] (see wait(2)). ...

After exit(), the exit status must be transmitted to the parent process. There are three cases. If the parent has set SA_NOCLDWAIT, or has set the SIGCHLD handler to SIG_IGN, the status is discarded. If the parent was waiting on the child, it is notified of the exit status. In both cases the exiting process dies immediately. If the parent has not indicated that it is not interested in the exit status, but is not waiting, the exiting process turns into a "zombie" process (which is nothing but a container for the single byte representing the exit status) so that the parent can learn the exit status when it later calls one of the wait(2) functions.

不,exit() 不会终止父进程。 exit() 函数将终止当前进程,并return 将退出代码传给父进程。因此,如果您使用 exit(1),则退出代码 1 将 returned 到父进程。