ps – show processes in Unix/Linux

ps is one of the basic Unix commands that helps you access information about processes running on your system.

Show processes of the current user

Simply type “ps” in the command line to see which processes you’re currently running on your Unix/Linux system. As you can see from the listing, I’m running bash shell and then ps command.

[greys@redhat8 ~]$ ps
PID TTY TIME CMD
26344 pts/0 00:00:00 bash
26606 pts/0 00:00:00 ps

Show full information about processes

Using the -f option for ps you can gain additional useful information on each process in the listing: usernames (UID), process ID (PID), parent process ID (PPID) and full command lines (not just the process name). In this example I’m still looking at my own processes, but really -f is a modifier – so you can use in combination with any other ps command options:

[greys@redhat8 ~]$ ps -f
UID PID PPID C STIME TTY TIME CMD
greys 26344 26343 0 19:03 pts/0 00:00:00 -bash
greys 26589 26344 0 19:16 pts/0 00:00:00 ps -f

One immediately obvious thing from this listing is that bash (process ID 26344) is actually the parent process of my ps -f command (see how it shows PPID of 26344) – this makes perfect sense, obviously: we ran ps by typing a command in the bash shell prompt.

Show all the processes on the system

This will show not only your own processes, but all the other processes running under different users as well. Combined with the -f option, this gives us a fairly useful output:

[greys@redhat8 ~]$ ps -ef | more
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Mar26 ? 00:00:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 18
root 2 0 0 Mar26 ? 00:00:00 [kthreadd]
root 3 2 0 Mar26 ? 00:00:00 [rcu_gp]
root 4 2 0 Mar26 ? 00:00:00 [rcu_par_gp]
root 6 2 0 Mar26 ? 00:00:00 [kworker/0:0H-kblockd]
root 8 2 0 Mar26 ? 00:00:00 [mm_percpu_wq]
root 9 2 0 Mar26 ? 00:00:03 [ksoftirqd/0]
root 10 2 0 Mar26 ? 00:00:02 [rcu_sched]
root 11 2 0 Mar26 ? 00:00:00 [rcu_bh]
root 12 2 0 Mar26 ? 00:00:00 [migration/0]
root 13 2 0 Mar26 ? 00:00:00 [watchdog/0]
root 14 2 0 Mar26 ? 00:00:00 [cpuhp/0]
root 16 2 0 Mar26 ? 00:00:00 [kdevtmpfs]
root 17 2 0 Mar26 ? 00:00:00 [netns]
root 18 2 0 Mar26 ? 00:00:00 [kauditd]
root 19 2 0 Mar26 ? 00:00:00 [khungtaskd]
root 20 2 0 Mar26 ? 00:00:00 [oom_reaper]
root 21 2 0 Mar26 ? 00:00:00 [writeback]
root 22 2 0 Mar26 ? 00:00:00 [kcompactd0]
root 23 2 0 Mar26 ? 00:00:00 [ksmd]
root 24 2 0 Mar26 ? 00:00:00 [khugepaged]
root 25 2 0 Mar26 ? 00:00:00 [crypto]
...
root 26326 847 0 19:03 ? 00:00:00 sshd: greys [priv]
greys 26331 1 0 19:03 ? 00:00:00 /usr/lib/systemd/systemd --user
root 26335 2 0 19:03 ? 00:00:00 [kworker/0:3-events_power_efficient]
greys 26336 26331 0 19:03 ? 00:00:00 (sd-pam)
greys 26342 26331 0 19:03 ? 00:00:00 /usr/bin/pulseaudio --daemonize=no
greys 26343 26326 0 19:03 ? 00:00:00 sshd: greys@pts/0
greys 26344 26343 0 19:03 pts/0 00:00:00 -bash
greys 26402 26331 0 19:03 ? 00:00:00 /usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation --syslog-o
nly
root 26535 2 0 19:14 ? 00:00:00 [kworker/0:0-ata_sff]
root 26621 2 0 19:19 ? 00:00:00 [kworker/0:1-ata_sff]
root 26629 797 0 19:19 ? 00:00:00 sleep 60
greys 26632 26344 0 19:20 pts/0 00:00:00 ps -ef
greys 26633 26344 0 19:20 pts/0 00:00:00 more

INTERESTING: this output shows a few more processes running under my username greys: they were not started directly by me but are still needed and managed under my user.

Show securty contexts in RedHat/CentOS/Fedora

If your system is SELinux capable, you can get SELinux context information with the Z flag to the ps command. Here I’m looking at the contexts of everything running under my own username:

[greys@redhat8 ~]$ ps -Z
LABEL PID TTY TIME CMD
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 26344 pts/0 00:00:00 bash
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 26510 pts/0 00:00:00 ps

See Also