Bug 486602 - Inconsistent ppid in state system
Summary: Inconsistent ppid in state system
Status: NEW
Alias: None
Product: Tracecompass
Classification: Tools
Component: LTTng (show other bugs)
Version: 2.0.0   Edit
Hardware: PC Linux
: P3 normal
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Project Inbox CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-01-26 15:45 EST by Matthew Khouzam CLA
Modified: 2016-05-10 12:04 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Khouzam CLA 2016-01-26 15:45:11 EST
When a thread exits. all its children threads need to be re-assigned to ppid : 1 (init)
Comment 1 Eclipse Genie CLA 2016-05-09 11:49:26 EDT
New Gerrit change created: https://git.eclipse.org/r/72309
Comment 2 Patrick Tasse CLA 2016-05-10 10:51:22 EDT
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
Comment 3 Loic Prieur-Drevon CLA 2016-05-10 10:59:12 EDT
(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?
Comment 4 Patrick Tasse CLA 2016-05-10 11:31:18 EDT
Before:

init─┬─
     ├─lightdm─┬─
     │         ├─lightdm─┬─init─┬─
     │         │         │      ├─gnome-terminal─┬─bash───bash───sh─┬─gedit───8*[{gedit}]
     │         │         │      │                │                  └─pstree

After:

init─┬─
     ├─lightdm─┬─
     │         ├─lightdm─┬─init─┬─
     │         │         │      ├─gedit───7*[{gedit}]
Comment 5 Raphael Beamonte CLA 2016-05-10 12:04:15 EDT
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