From fca9a390db4c965b4606dd85838460841bd4ab14 Mon Sep 17 00:00:00 2001 From: Fabricio Voznika Date: Wed, 26 Sep 2018 21:58:54 -0700 Subject: 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 --- pkg/sentry/control/proc.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'pkg/sentry') diff --git a/pkg/sentry/control/proc.go b/pkg/sentry/control/proc.go index 68d3b179b..b120471cb 100644 --- a/pkg/sentry/control/proc.go +++ b/pkg/sentry/control/proc.go @@ -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(), -- cgit v1.2.3