diff --git a/runsc/boot/procfs/dump.go b/runsc/boot/procfs/dump.go index 8ecbcca99..54214e21d 100644 --- a/runsc/boot/procfs/dump.go +++ b/runsc/boot/procfs/dump.go @@ -49,6 +49,7 @@ type UIDGID struct { type Status struct { Comm string `json:"comm,omitempty"` PID int32 `json:"pid,omitempty"` + PPID int32 `json:"ppid,omitempty"` UID UIDGID `json:"uid,omitempty"` GID UIDGID `json:"gid,omitempty"` VMSize uint64 `json:"vm_size,omitempty"` @@ -208,12 +209,17 @@ func getFDLimit(ctx context.Context, pid kernel.ThreadID) (limits.Limit, error) return limits.Limit{}, fmt.Errorf("could not find limit set for pid %s", pid) } -func getStatus(t *kernel.Task, mm *mm.MemoryManager, pid kernel.ThreadID) Status { +func getStatus(t *kernel.Task, mm *mm.MemoryManager, pid kernel.ThreadID, pidns *kernel.PIDNamespace) Status { creds := t.Credentials() uns := creds.UserNamespace + ppid := kernel.ThreadID(0) + if parent := t.Parent(); parent != nil { + ppid = pidns.IDOfThreadGroup(parent.ThreadGroup()) + } return Status{ Comm: t.Name(), PID: int32(pid), + PPID: int32(ppid), UID: UIDGID{ Real: uint32(creds.RealKUID.In(uns).OrOverflow()), Effective: uint32(creds.EffectiveKUID.In(uns).OrOverflow()), @@ -265,7 +271,7 @@ func Dump(t *kernel.Task, pid kernel.ThreadID, pidns *kernel.PIDNamespace) (Proc // We don't need to worry about fake cgroup controllers as that is not // supported in runsc. Cgroup: t.GetCgroupEntries(), - Status: getStatus(t, mm, pid), + Status: getStatus(t, mm, pid, pidns), Stat: getStat(t, pid, pidns), }, nil } diff --git a/runsc/container/trace_test.go b/runsc/container/trace_test.go index 353de58e1..2a117f4c8 100644 --- a/runsc/container/trace_test.go +++ b/runsc/container/trace_test.go @@ -413,6 +413,10 @@ func TestProcfsDump(t *testing.T) { } } + if wantPPID := int32(0); procfsDump[0].Status.PPID != wantPPID { + t.Errorf("expected PPID to be %d, but got %d", wantPPID, procfsDump[0].Status.PPID) + } + if wantName := "sleep"; procfsDump[0].Status.Comm != wantName { t.Errorf("expected Comm to be %q, but got %q", wantName, procfsDump[0].Status.Comm) }