linux process – Is SIGHUP Sent to Orphaned Process and Why Doesn’t It Terminate?

linuxprocesssighup

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 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)

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?

Best Answer

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.