What happens to a unix session when the session leader exits?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite
1












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?







share|improve this question




















  • Some related questions are unix.stackexchange.com/questions/405755 , unix.stackexchange.com/questions/84737 , unix.stackexchange.com/questions/18166 , and unix.stackexchange.com/questions/282973 .
    – JdeBP
    Nov 28 '17 at 10:16










  • @JdeBP interesting links, but it's still hard to say what is expected to happen if the session leader exits. Even considered that the session leader might not be a shell.
    – Giacomo Tesio
    Nov 28 '17 at 10:52














up vote
1
down vote

favorite
1












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?







share|improve this question




















  • Some related questions are unix.stackexchange.com/questions/405755 , unix.stackexchange.com/questions/84737 , unix.stackexchange.com/questions/18166 , and unix.stackexchange.com/questions/282973 .
    – JdeBP
    Nov 28 '17 at 10:16










  • @JdeBP interesting links, but it's still hard to say what is expected to happen if the session leader exits. Even considered that the session leader might not be a shell.
    – Giacomo Tesio
    Nov 28 '17 at 10:52












up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





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?







share|improve this question












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?









share|improve this question











share|improve this question




share|improve this question










asked Nov 28 '17 at 9:35









Giacomo Tesio

4551615




4551615











  • Some related questions are unix.stackexchange.com/questions/405755 , unix.stackexchange.com/questions/84737 , unix.stackexchange.com/questions/18166 , and unix.stackexchange.com/questions/282973 .
    – JdeBP
    Nov 28 '17 at 10:16










  • @JdeBP interesting links, but it's still hard to say what is expected to happen if the session leader exits. Even considered that the session leader might not be a shell.
    – Giacomo Tesio
    Nov 28 '17 at 10:52
















  • Some related questions are unix.stackexchange.com/questions/405755 , unix.stackexchange.com/questions/84737 , unix.stackexchange.com/questions/18166 , and unix.stackexchange.com/questions/282973 .
    – JdeBP
    Nov 28 '17 at 10:16










  • @JdeBP interesting links, but it's still hard to say what is expected to happen if the session leader exits. Even considered that the session leader might not be a shell.
    – Giacomo Tesio
    Nov 28 '17 at 10:52















Some related questions are unix.stackexchange.com/questions/405755 , unix.stackexchange.com/questions/84737 , unix.stackexchange.com/questions/18166 , and unix.stackexchange.com/questions/282973 .
– JdeBP
Nov 28 '17 at 10:16




Some related questions are unix.stackexchange.com/questions/405755 , unix.stackexchange.com/questions/84737 , unix.stackexchange.com/questions/18166 , and unix.stackexchange.com/questions/282973 .
– JdeBP
Nov 28 '17 at 10:16












@JdeBP interesting links, but it's still hard to say what is expected to happen if the session leader exits. Even considered that the session leader might not be a shell.
– Giacomo Tesio
Nov 28 '17 at 10:52




@JdeBP interesting links, but it's still hard to say what is expected to happen if the session leader exits. Even considered that the session leader might not be a shell.
– Giacomo Tesio
Nov 28 '17 at 10:52










1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










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:



  • notes.shichao.io/apue/ch9

  • Chapter 10 "Processes" in The Linux Kernel by Andries Brouwer (2003).


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".







share|improve this answer






















  • 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.
    – Giacomo Tesio
    Nov 28 '17 at 14:37










  • @GiacomoTesio: See added quotation from The Linux Kernel.
    – AlexP
    Nov 28 '17 at 16:09











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f407448%2fwhat-happens-to-a-unix-session-when-the-session-leader-exits%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted










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:



  • notes.shichao.io/apue/ch9

  • Chapter 10 "Processes" in The Linux Kernel by Andries Brouwer (2003).


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".







share|improve this answer






















  • 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.
    – Giacomo Tesio
    Nov 28 '17 at 14:37










  • @GiacomoTesio: See added quotation from The Linux Kernel.
    – AlexP
    Nov 28 '17 at 16:09















up vote
3
down vote



accepted










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:



  • notes.shichao.io/apue/ch9

  • Chapter 10 "Processes" in The Linux Kernel by Andries Brouwer (2003).


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".







share|improve this answer






















  • 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.
    – Giacomo Tesio
    Nov 28 '17 at 14:37










  • @GiacomoTesio: See added quotation from The Linux Kernel.
    – AlexP
    Nov 28 '17 at 16:09













up vote
3
down vote



accepted







up vote
3
down vote



accepted






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:



  • notes.shichao.io/apue/ch9

  • Chapter 10 "Processes" in The Linux Kernel by Andries Brouwer (2003).


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".







share|improve this answer














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:



  • notes.shichao.io/apue/ch9

  • Chapter 10 "Processes" in The Linux Kernel by Andries Brouwer (2003).


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".








share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 28 '17 at 16:12

























answered Nov 28 '17 at 11:28









AlexP

6,656924




6,656924











  • 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.
    – Giacomo Tesio
    Nov 28 '17 at 14:37










  • @GiacomoTesio: See added quotation from The Linux Kernel.
    – AlexP
    Nov 28 '17 at 16:09

















  • 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.
    – Giacomo Tesio
    Nov 28 '17 at 14:37










  • @GiacomoTesio: See added quotation from The Linux Kernel.
    – AlexP
    Nov 28 '17 at 16:09
















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.
– Giacomo Tesio
Nov 28 '17 at 14:37




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.
– Giacomo Tesio
Nov 28 '17 at 14:37












@GiacomoTesio: See added quotation from The Linux Kernel.
– AlexP
Nov 28 '17 at 16:09





@GiacomoTesio: See added quotation from The Linux Kernel.
– AlexP
Nov 28 '17 at 16:09


















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f407448%2fwhat-happens-to-a-unix-session-when-the-session-leader-exits%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?