Community
Participate
Working Groups
When a thread exits. all its children threads need to be re-assigned to ppid : 1 (init)
New Gerrit change created: https://git.eclipse.org/r/72309
I wonder if this is the correct behavior. I tried in a shell: > sh sh pid is 747 sh> gedit & gedit pid is 1401 gedit ppid is 747 sh> kill -9 747 gedit ppid is now 5683 ***not 1*** pid 5683 is 'init --user' owned by me pid 1 is '/sbin/init' owned by root
(In reply to Patrick Tasse from comment #2) > I wonder if this is the correct behavior. > > I tried in a shell: > > > sh > > sh pid is 747 > > sh> gedit & > > gedit pid is 1401 > gedit ppid is 747 > > sh> kill -9 747 > > gedit ppid is now 5683 ***not 1*** > > pid 5683 is 'init --user' owned by me > pid 1 is '/sbin/init' owned by root Can you give the ps tree for gedit before and after killing its parent?
Before: init─┬─ ├─lightdm─┬─ │ ├─lightdm─┬─init─┬─ │ │ │ ├─gnome-terminal─┬─bash───bash───sh─┬─gedit───8*[{gedit}] │ │ │ │ │ └─pstree After: init─┬─ ├─lightdm─┬─ │ ├─lightdm─┬─init─┬─ │ │ │ ├─gedit───7*[{gedit}]
Hm, after further reading, it seems that historically, the process 1 was indeed the "parent of all orphaned". But since 3.4, the Linux kernel has changed on that matter. I quote: "The systemd developers added the ability for processes to set themselves up as "subreapers". From Linux 3.4 onwards processes can issue the prctl() system call with the PR_SET_CHILD_SUBREAPER option, and as a result they, not process #1, will become the parent of any of their orphaned grandchildren processes." [1] You can check that information from the man page of prctl. It is thus difficult to directly know who will be the parent of a process when its parent is killed, as it is not anymore the process "1" that inherit all, and trace events do not give that information. Perhaps the best solution would be an upgrade on the sched_process_exit tracepoint, to add the new parent's tid ? But it's out of the scope of Trace Compass. [1]: https://unix.stackexchange.com/questions/149319/new-parent-process-when-the-parent-process-dies