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,
sleep process orphaned? (I think yes, Figure 34.3)
is SIGHUP sent to the
sleep process because it becomes orphaned? (I guess it is, by the quote)
why doesn't the
sleep process terminate because SIGHUP is sent to it? (I am not sure)
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?
From The Open Group Base Specifications Issue 7, 2018 edition, System Interfaces, under
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.
(sleep 123 &),
sleep 123 &process becomes the only process in its own process group, and it has been reparented to some other process outside its process session, so it and its group are both orphaned. — Nov 27, 2018 at 13:29
setpgid(); a process is never made a group leader automatically -- it has to say that it wants to be a group (or session) leader. That's why all processes started from a user's interactive shell get SIGHUP when that shell terminates. — Nov 27, 2018 at 13:59
External links referenced by this document: