Reputation: 1733
Not long ago, I wondered about the question: why are all processes killed when you close a terminal on Linux, and not passed to the "init" process (with pid 1)? Because, all child processes are adopted by "init" process after termination of the parent. Please, help me understand difference and the errors in my reasoning.
And also:
If it's possible, then can we use a system call to stop this happening? I think, that for this the programs need use setsid()
, but in practice it's not correct.
Upvotes: 1
Views: 652
Reputation: 72639
As explained by cnicutar, it's due to the SIGHUP
sent to all processes in the process group associated with the controlling terminal. You may either install a handler for this signal or ignore it completely. For arbitrary programs, you can start them with the nohup
utility designed for this purpose.
You can also place the process in a new process group without a controlling terminal.
Upvotes: 2
Reputation: 2318
i think this will help you to understand http://www.digipedia.pl/usenet/thread/18802/10189/
Upvotes: 0
Reputation: 182619
why on close terminal on linux all his processes will terminated, but not passed to "init" process (with pid 1)
The processes are losing their controlling terminal so the kernel sends them a SIGHUP
. The default action of SIGHUP
is to terminate the process.
Upvotes: 1