开发者

why background process group die when terminal closed

开发者 https://www.devze.com 2023-02-22 05:27 出处:网络
According to this faq (and by many other books): ftp://rtfm.mit.edu/pub/faqs/unix-faq/programmer/faq 1.15 Why doesn\'t my process get SIGHUP when its parent dies?

According to this faq (and by many other books):

ftp://rtfm.mit.edu/pub/faqs/unix-faq/programmer/faq

1.15 Why doesn't my process get SIGHUP when its parent dies?

SIGHUP won't be sent to background processes when none of them is " stopped ".

but we all know that if SIGHUP isn't capt开发者_StackOverflow中文版ured in background processes, they will die when you close the terminal(or connection like ssh).

i.e. CTRL+Z - bg isn't enough for a process to survive when terminal is closed.

But why? Any wisdom is appreciated!


There is an easy solution for it. Use nohup before running the command.


After googling a bit. I assume the HUP signal which result in exiting of background processes is from shell.

Here are the steps:

  1. Terminal is closed, bash receives SIGHUP from kernel(driver)

  2. Bash exits by default upon receipt of a SIGHUP. Before exiting, it resends the SIGHUP to all jobs, running or stopped

  3. All jobs, including background processes, exit if they don't capture SIGHUP

0

精彩评论

暂无评论...
验证码 换一张
取 消