2

Opening a new terminal and typing the command firefox& inside, ps -l gives :

4 R  1000 23132 23104 99  80   0 - 2177945 -    pts/27   00:00:07 firefox

If the shell is closed with the command exit, the firefox child process stays open !

Was it always the case ? Isn't firefox supposed to be closing as well ? Is there something new in a recent kernel or something i'm missing ?

The result of ps -el|grep firefox is then :

4 S  1000 23132     1 14  80   0 - 2233312 poll_s ?      00:00:21 firefox

The PPID has been changed to 1.

What is responsible for this PPID change to 1 ?

EDIT : Oh I've just realised that closing the terminal and closing the shell have very different results : closing the terminal does close all the child processes, but not when the shell is closed with the exit command... No idea why. (Closing terminal is sending SIGTERM to all child processes ? But closing shell is leaving orphans ?)

  • parent process died, so it changes PPID to the closest reaper process. So kernel will maintain a strict process tree. – 炸鱼薯条德里克 Oct 18 '18 at 4:48
2

Is there something new in a recent kernel or something I'm missing?

No, if a process exits, its children keep running, their parent process just gets changed to init (PID 1). Or some other, system-dependent process, look up e.g. "subreapers" on Linux.

That's always been the case, it's what allows nohup to work usefully, as well the aged process of turning a process into a daemon by forking twice, calling setsid() and exiting the parent processes.

Closing a terminal session might send SIGHUP to the remaining processes there, but they're free to ignore it (and that's what nohup does). Also, systemd can be configured to kill any lingering processes when a terminal login session exits, but you're probably running firefox within X from a terminal emulator, so that doesn't apply.

  • Thanks, but if firefox is launched without the &, and the terminal is closed, firefox will close as well. What is happening there ? SIGTERM for terminal and all child processes ? – bob dylan Oct 18 '18 at 5:03
  • Same if the process is stopped by for example SIGTSTP (ctrl + z) exiting is also closing it, what is happening really ? Where is the official doc about this behavior ? – bob dylan Oct 18 '18 at 5:11
  • @bobdylan, I can never remember the exact details of the signals sent when a terminal closes (and what part of the system sends them to what processes), you'll have to ask another question about that. – ilkkachu Oct 18 '18 at 5:18
  • I edited my initial message, I was assuming that closing terminal and closing shell had the same effect. They do not. Still unclear for me though... – bob dylan Oct 18 '18 at 5:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.