8

I'm trying to properly emulate POSIX signals handling and job control for my pet operating system, but it's not clear to me what should happen to a session after the session leader exits.

I cannot find documentation related to what happens to the session and its process if, for example, a child kills the session leader while several background processes and a different foreground process are running.

My tests show that all the process in the session are killed, but how?
Do they receive a specific signal?
Is this case specified in the POSIX standard? And if so, can you provide some references?

2

1 Answer 1

10

You are not the only one puzzled by POSIX sessions; Lennart Poettering (he of systemd fame) is puzzled too.

As far as anybody can tell, when a session leader dies, init inherits the orphaned session and

  • All session member processes in the foreground process group (if any) receive a SIGHUP.

  • Session member processes who are not in the foreground group don't receive any signal.

See also:

If the terminal goes away by modem hangup, and the line was not local, then a SIGHUP is sent to the session leader. [...] When the session leader dies, a SIGHUP is sent to all processes in the foreground process group. [...] Thus, if the terminal goes away and the session leader is a job control shell, then it can handle things for its descendants, e.g. by sending them again a SIGHUP. If on the other hand the session leader is an innocent process that does not catch SIGHUP, it will die, and all foreground processes get a SIGHUP.

Andries Brower, The Linux Kernel, section 10.3 "Sessions".

2
  • As for "All session member processes in the foreground process group (if any) receive a SIGHUP.": do you know who send the SIGHUP? In unix.stackexchange.com/questions/84737/… it seems that bash send the signal... and this would invalidate part of your answer. Nov 28, 2017 at 14:37
  • @GiacomoTesio: See added quotation from The Linux Kernel.
    – AlexP
    Nov 28, 2017 at 16:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .