On Lubuntu 18.04, if I click the desktop menu, and lxterminal in it, and run the the following in the terminal emulator window, I will get
$ pstree -a -p -s $$
systemd,1 --system --deserialize 19
└─lightdm,661
└─lightdm,862 --session-child 12 19
└─lxsession,944 -s Lubuntu -e LXDE
└─lxpanel,1087 --profile Lubuntu
└─lxterminal,23017
└─bash,23020
└─pstree,26853 -a -p -s 23020
If I hit Alt+F2, and run lxterminal and run the following in the terminal emulator window, I will get
$ pstree -a -p -s $$
systemd,1 --system --deserialize 19
└─lxterminal,1480
└─bash,27000
└─pstree,27013 -a -p -s 27000
How does the second make lxterminal run as a child of systemd? Is it done by orphaning the lxterminal process and reparenting it to systemd?
What were the original parent and grandparent of the lxterminal process?
My question is actually more general: how does Alt+F2 run any command as child of the init process?
Where is the relevant source code?
My suspicion:
when I hit alt_F2, I guess it is equivalent to click the menu panel of the desktop environment and then select "Run". I guess what happens in the equivalent is
The lxpanel process forks a process to show the Run window for asking what command to run, which then exits after forking a second process to run the specified command. That reparents the process executing the specified command to the init process. (Unlike creating a daemon process, the process executing the specified command doesn't start a new process session.)
Since lxpanel is in the process session led by lxession,944, and has no controlling terminal, the process running the specified command is in the same session and also has no controlling terminal. There seems to be no worry about being sent SIGHUP, if not reparenting the process executing the specified command to the init process, by terminating the middle process early.
So what is the purpose of reparenting the process executing the specified command to the init process, by terminating the middle process early?