简体   繁体   English

在C语言中,如果父进程终止,那么子进程会自动终止吗?

[英]In C, if a parent process terminates, then will the child process automatically terminate?

If I use fork() to spawn a child process, then will the child process automatically terminate once the parent process terminates? 如果我使用fork()生成子进程,那么一旦父进程终止,子进程会自动终止吗? Or must this be programmed? 还是必须对此进行编程?

This isn't really ac question, it's an O/S question. 这不是一个真正的交流问题,而是一个操作系统问题。

In Windows, a process will continue until either it calls ExitProcess or when it has performed enough CPU RETs that there's nothing left in the call stack. 在Windows中,一个进程将继续进行,直到它调用ExitProcess或执行了足够的CPU RET,以至于调用堆栈中没有剩余。

In Unix, the process will continue and run as a subprocess of init . 在Unix中,该过程将继续并作为init的子过程运行。

On both O/S's, a user with enough permissions can kill the process. 在两个操作系统上,具有足够权限的用户都可以终止该进程。

Threads, on the other hand, are a different matter-- they will terminate when the process terminates. 另一方面,线程是另一回事-当进程终止时,它们将终止。

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

相关问题 在 C 语言的 Linux 编程中,子进程可以等待父进程终止吗? - Can a child process wait for the parent process to terminate in Linux programming in C? SIGTSTP处理程序会终止父进程和子进程 - SIGTSTP Handler terminates both parent and child process 确保父进程在子进程之前终止 - Ensuring that parent process terminates before child 等待子进程是否终止-C - Waiting for child process to terminate, or not - C 在ac程序中,整个过程是否在主线程终止时终止? - In a c program, does the whole process terminates when the main thread terminate? 当父进程等待子进程终止时,子进程如何杀死父进程? - How can child kill parent process while parent process waits until child process to terminate? 创建了两个子进程。 父进程应该一直执行到一个子进程终止。 我如何在 c 中编写这个程序? - Two child process are created. The parent process should execute until one child process terminates. How do I write this program in c? 使用SIGTERM对子进程调用kill会终止父进程,但使用SIGKILL调用它会使父进程保持活动状态 - Calling kill on a child process with SIGTERM terminates parent process, but calling it with SIGKILL keeps the parent alive C Pthreads - 父/子进程 - C Pthreads - Parent/Child process 父进程和子进程 - parent process, and a child process
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM