使用 ps 命令处理组 ID

Proces group id with ps command

我尝试 ps 使用不同类型的开关,例如-A、aux、ef 等等,但我似乎无法找到正确的开关组合来告诉我进程 ID (PID)、父进程 ID (PPID)、进程组 ID (PGID) 和会话 ID同一输出中进程的 (SID)。

给你:

$ 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