I am trying to understand what happens when we log out of Linux (Ubuntu specifically):
How does a process initially request/notify the logging out process to perform logging out (by sending some signals, or some other IPC means)? What is the program run by the logging out process? What is usually the program run by the requesting/notifying process?
What processes will the logging out process kill and what not? (There are ways to make processes started after logging in survive logging out, and how do they manage to do that? Making a process not having a controlling terminal seems to be a way, but most of the processes killed by logging out in the following examples don't have a controlling terminal)
How does the logging out process kill those processes (by sending some signals, or some other IPC means)?
Consider three cases: virtual console and desktop environment and SSH. (The first two are provided by the OS, and the third isn't, though all are running in user space)
When I log in virtual console, I get the following ancestry processes from the login shell:
1 systemd 721 login 26284 bash
After I log out, processes
721 loginand below disappear.
On Lubuntu 18.04, when I log in lightdm and LXDE, and run lxterminal from the desktop's panel and get the ancestor processes from the following command in the lxterminal window:
$ ps -paus $$ systemd,1 --system --deserialize 19 `-lightdm,661 `-lightdm,27302 --session-child 13 24 `-lxsession,27309,testme -s Lubuntu -e LXDE `-lxpanel,27399 --profile Lubuntu `-lxterminal,27565 `-bash,27568 `-pstree,27594 -paus 27568
When I log out, the processes
lightdm,27302and below disappear.
After I ssh into Lubuntu 18.04:
$ pstree -a -p -s $$ systemd,1 --system --deserialize 19 └─sshd,669 -D └─sshd,22838 └─sshd,22979 └─bash,22980 └─pstree,30610 -a -p -s 22980
After I log out, all the processes starting from
sshd,22838to below disappear.