ps -aeo pid,cgroup,command
ps is the classic command for listing the processes running on the machine. Used without options, it gives you a minimum of information about the processes associated with your terminal:
$ ps
PID TTY TIME CMD
352 pts/0 00:00:00 ps
32052 pts/0 00:00:00 bash
Typically, this output will show only the ps command itself, and its parent shell (bash). How come the PID for the ps command (352) is less than the PID of its parent (32052)? That’s because after PIDs have reached a specified limit (by default it’s 32768) the numbers wrap around and the PIDs get recycled. I didn’t deliberately engineer that result, it just happened to come out that way.
ps has a large and very confusing set of options, partly because it’s trying to remain backwards compatible with both of its progenitors (the BSD and System V versions) and partly because, well, it’s just got a lot of options. Some of them control which processes are listed; some control how much detail is shown. I suspect that most people just remember two or three combinations of options that they find useful, and stick with those.
ps in depth
The -f option gives a full listing:
$ ps -f
UID PID PPID C STIME TTY TIME CMD
chris 4770 32052 0 12:33 pts/0 00:00:00 ps -f
chris 32052 32042 0 Mar19 pts/0 00:00:00 bash
…and the -l option gives even more (rather like the -l option of ls):
$ ps -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY
TIME CMD
0 R 1000 4771 32052 0 80 0 - 3475 - pts/0
00:00:00 ps
0 S 1000 32052 32042 0 80 0 - 6937 wait pts/0
00:00:00 bash
The divided heritage of ps causes confusion. For example the two commands
$ ps -elf
$ ps aux
produce approximately the same output.
The first uses System V syntax, the second uses BSD syntax (note the absence of a hyphen). They do not, however, show exactly the same output fields. I suspect that most administrators memorise two or three useful combinations of options and stick with those. That’s what I do!
If you want detailed control over the output fields use the -o option. This example shows the process ID, group ID, and
command line:
$ ps -o pid,gid,cmd
PID GID CMD
6260 1000 ps -o pid,gid,cmd
32052 1000 bash
There are LOTS of output columns you can select here; see the STANDARD FORMAT SPECIFIERS section of the man page for the details.
The -e option lists every process, but you can also get finer control over which processes are listed. For example,
$ ps --ppid 1
shows those processes whose parent is PID 1 (note the use of the GNU-style command option with the double hyphen!), or to show just the processes running as chris:
$ ps -u chris