In The Linux Programming Interface:
SIGHUP is generated when a process group becomes orphaned.
In an interactive bash process,
$ ( sleep 123 &)
will first forks a subshell, and the subshell then forks to execute sleep 123 &. The subshell exits immediately without waiting sleep 123 to finish because of &. At that time,
-
is the
sleepprocess orphaned? (I think yes, Figure 34.3) -
is SIGHUP sent to the
sleepprocess because it becomes orphaned? (I guess it is, by the quote) -
why doesn’t the
sleepprocess terminate because SIGHUP is sent to it? (I am not sure)
Thanks.
I also have similar question when create a daemon process by first forking a child process and then the child process forking a grandchild and exiting immediately. The grandchild becomes orphaned and isn’t SIGHUP sent to it, making it terminate?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
From The Open Group Base Specifications Issue 7, 2018 edition, System Interfaces, under _exit:
- If the process is a controlling process, the SIGHUP signal shall be sent to each process in the foreground process group of the controlling terminal belonging to the calling process.
- If the process is a controlling process, the controlling terminal associated with the session shall be disassociated from the session, allowing it to be acquired by a new controlling process.
- If the exit of the process causes a process group to become orphaned, and if any member of the newly-orphaned process group is stopped, then a SIGHUP signal followed by a SIGCONT signal shall be sent to each process in the newly-orphaned process group.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0