Return correct parent PID

Old code was returning ID of the thread that created
the child process. It should be returning the ID of
the parent process instead.

PiperOrigin-RevId: 214720910
Change-Id: I95715c535bcf468ecf1ae771cccd04a4cd345b36
This commit is contained in:
Fabricio Voznika
2018-09-26 22:00:04 -07:00
committed by Shentubot
parent a003e041c8
commit fca9a390db
+7 -4
View File
@@ -269,11 +269,14 @@ func Processes(k *kernel.Kernel, out *[]*Process) error {
continue
}
ppid := kernel.ThreadID(0)
if tg.Leader().Parent() != nil {
ppid = ts.Root.IDOfThreadGroup(tg.Leader().Parent().ThreadGroup())
}
*out = append(*out, &Process{
UID: tg.Leader().Credentials().EffectiveKUID,
PID: pid,
// If Parent is null (i.e. tg is the init process), PPID will be 0.
PPID: ts.Root.IDOfTask(tg.Leader().Parent()),
UID: tg.Leader().Credentials().EffectiveKUID,
PID: pid,
PPID: ppid,
STime: formatStartTime(now, tg.Leader().StartTime()),
C: percentCPU(tg.CPUStats(), tg.Leader().StartTime(), now),
Time: tg.CPUStats().SysTime.String(),