‘ps’ arguments to display PID, PPID, PGID, and SID collectively

processps

I tried ps with different kinds of switches e.g. -A, aux, ef, and so forth but I cannot seem to find the right combination of switches that will tell me the Process ID (PID), Parent Process ID (PPID), Process Group ID (PGID), and the Session ID (SID) of a process in the same output.

Best Answer

Here you go:

$ ps  xao pid,ppid,pgid,sid | head
  PID  PPID  PGID   SID
    1     0     1     1
    2     0     0     0
    3     2     0     0
    6     2     0     0
    7     2     0     0
   21     2     0     0
   22     2     0     0
   23     2     0     0
   24     2     0     0

If you want to see the process' name as well, use this:

$ ps  xao pid,ppid,pgid,sid,comm | head
  PID  PPID  PGID   SID COMMAND
    1     0     1     1 init
    2     0     0     0 kthreadd
    3     2     0     0 ksoftirqd/0
    6     2     0     0 migration/0
    7     2     0     0 watchdog/0
   21     2     0     0 cpuset
   22     2     0     0 khelper
   23     2     0     0 kdevtmpfs
   24     2     0     0 netns
Related Question