简体   繁体   English

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

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

If I call exit(1) in the child process, will this action cause parent process to terminate as well?如果我在子进程中调用 exit(1) ,此操作是否也会导致父进程终止? Or simply only child process is terminated by exit(1)?或者只是只有子进程被 exit(1) 终止?

man exit

This shows由此可见

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)). exit() 函数会导致正常的 [当前/子] 进程终止,并将 [退出] 状态的值返回给父 [进程] (请参阅 wait(2))。 ... ...

After exit(), the exit status must be transmitted to the parent process.在 exit() 之后,必须将退出状态传输到父进程。 There are three cases.有三种情况。 If the parent has set SA_NOCLDWAIT, or has set the SIGCHLD handler to SIG_IGN, the status is discarded.如果父已设置 SA_NOCLDWAIT,或已将 SIGCHLD 处理程序设置为 SIG_IGN,则该状态将被丢弃。 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.如果父进程没有表明它对退出状态不感兴趣,而是不等待,退出进程就会变成一个“僵尸”进程(它只不过是代表退出状态的单个字节的容器),以便父级可以在稍后调用 wait(2) 函数之一时了解退出状态。

exit does not cause the parent to also exit. exit不会导致父级也退出。 It causes normal process termination for the current process.它会导致当前进程的正常进程终止。

No, the exit() does not terminate the parent process.不,exit() 不会终止父进程。 The exit() function will terminate the current process, and return the exit code to the parent process. exit() 函数将终止当前进程,并将退出代码返回给父进程。 So, if you use exit(1), then the exit code 1 will be returned to the parent process.因此,如果您使用 exit(1),则退出代码 1 将返回给父进程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何向进程发送信号以导致调用exit()并终止 - How to send a signal to a process to cause call to exit() and terminate exit()无法终止进程吗? - Can exit() fail to terminate process? C语言:孩子不会退出,也不会终止,也不会杀死我的父进程 - C language: Children don't exit, nor terminate and are not killed my parent process too 在C语言中,如果父进程终止,那么子进程会自动终止吗? - In C, if a parent process terminates, then will the child process automatically terminate? 在 C 语言的 Linux 编程中,子进程可以等待父进程终止吗? - Can a child process wait for the parent process to terminate in Linux programming in C? 无法找到窗口父进程的窗口,也不能终止父进程 - Cannot FindWindow parent process' window, neither terminate parent 当父进程等待子进程终止时,子进程如何杀死父进程? - How can child kill parent process while parent process waits until child process to terminate? 在父进程出口处杀死子进程 - killing child processes at parent process exit 进程组中的进程是否应该与Unix / Linux中的父进程一起终止? - Should processes in process group terminate together with their parent in Unix/Linux? 子进程中的 exit(1) 在 Linux 中的父进程中返回 256 - exit(1) in child process returns 256 in the parent process in Linux
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM