Unix & Linux: 'ps' arguments to display PID, PPID, PGID, and SID collectively (2 Solutions!!)
Channel: Roel Van de Paar
Date: 2020-08-10

Unix & Linux: 'ps' arguments to display PID, PPID, PGID, and SID collectively


The Question: 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.

Solutions: Please watch the whole video to see all solutions, in order of how many people found them helpful

== This solution helped 72 people ==
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

With thanks & praise to God, and with thanks to the many people who have made this project possible! | Content (except music & images) licensed under cc by-sa 3.0 | Music: https://www.bensound.com/royalty-free-music | Images: https://stocksnap.io/license & others | With thanks to user terdon (https://unix.stackexchange.com/users/22222), user Raman Kathpalia (https://unix.stackexchange.com/users/97169), user Josh Correia (https://unix.stackexchange.com/users/340031), user JohnMerlino (https://unix.stackexchange.com/users/15378), user bobbogo (https://unix.stackexchange.com/users/246470), and the Stack Exchange Network (http://unix.stackexchange.com/questions/82724). Trademarks are property of their respective owners. Disclaimer: All information is provided "AS IS" without warranty of any kind. You are responsible for your own actions. Please contact me if anything is amiss at Roel D.OT VandePaar A.T gmail.com.