OSETC TECH

Linux: How to List All Running Processes

This post will guide you how to list all running processes in Linux. How to use ps commmand to show all running processes or check the process status on Linux.

List All Processes with Ps Command


If you want to show all running processes in your current Linux system, you can use the ps command with -aux option to achieve it. just type the following command:

# ps -aux | less

Outputs:

devops@devops-osetc:~/working$ ps aux | less
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.4 185248 4928 ? Ss Dec18 0:04 /sbin/init splash
root 2 0.0 0.0 0 0 ? S Dec18 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S Dec18 0:04 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S< Dec18 0:00 [kworker/0:0H]
root 7 0.0 0.0 0 0 ? S Dec18 1:11 [rcu_sched]
root 8 0.0 0.0 0 0 ? S Dec18 0:00 [rcu_bh]
root 9 0.0 0.0 0 0 ? S Dec18 0:00 [migration/0]
root 10 0.0 0.0 0 0 ? S< Dec18 0:00 [lru-add-drain]
root 11 0.0 0.0 0 0 ? S Dec18 0:00 [watchdog/0]
root 12 0.0 0.0 0 0 ? S Dec18 0:00 [cpuhp/0]
root 13 0.0 0.0 0 0 ? S Dec18 0:00 [kdevtmpfs]

List Every Process Using Standard Syntax


If you want to list every process on your system using standard syntax, just type one of the following command:

# ps -e
# ps -ef
# ps -eF
# ps -ely

Outputs:

devops@devops-osetc:~/working$ ps -e
PID TTY TIME CMD
1 ? 00:00:04 systemd
2 ? 00:00:00 kthreadd
3 ? 00:00:04 ksoftirqd/0
5 ? 00:00:00 kworker/0:0H
7 ? 00:01:11 rcu_sched
8 ? 00:00:00 rcu_bh
9 ? 00:00:00 migration/0
10 ? 00:00:00 lru-add-drain
11 ? 00:00:00 watchdog/0

List Every Process Running As Root


If you only want to see every process running as root in user format, you can use the following command:

# ps -U root -u root u

Outputs:

devops@devops-osetc:~/working$ ps -U root -u root u
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.4 185248 4928 ? Ss Dec18 0:04 /sbin/init splash
root 2 0.0 0.0 0 0 ? S Dec18 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S Dec18 0:04 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S< Dec18 0:00 [kworker/0:0H]
root 7 0.0 0.0 0 0 ? S Dec18 1:11 [rcu_sched]

List Process Run by User Devops


If you only want to list all process run by a given user devops in your Linux system, just type the following command:

# ps -u devops

Outputs:

devops@devops-osetc:~/working$ ps -u devops
PID TTY TIME CMD
2098 ? 00:00:00 systemd
2152 ? 00:00:00 (sd-pam)
2194 ? 00:00:00 gnome-keyring-d
2199 ? 00:00:00 upstart
2282 ? 00:00:00 upstart-udev-br
2286 ? 00:00:02 dbus-daemon
2298 ? 00:00:00 window-stack-br

Print a Process Tree


If you want to print a process tree in you system, you can use the ps command with -ejH option. type:

# ps -ejH

Outputs:

devops@devops-osetc:~/working$ ps -ejH
1061 1061 1061 tty1 00:00:00 agetty
1073 1073 1073 ? 00:01:14 mysqld
1085 1085 1085 ? 00:02:47 redis-server
1092 1092 1092 ? 00:00:00 sshd
2855 2855 2855 ? 00:00:00 sshd
2907 2855 2855 ? 00:00:02 sshd
2908 2908 2908 pts/1 00:00:01 bash
15665 15665 2908 pts/1 00:00:00 ps
1601 1601 1601 ? 00:00:01 rtkit-daemon
1650 1650 1650 ? 00:00:02 upowerd
1712 1712 1712 ? 00:00:00 colord
2098 2098 2098 ? 00:00:00 systemd
2152 2098 2098 ? 00:00:00 (sd-pam)
2194 2193 2193 ? 00:00:00 gnome-keyring-d
2606 2606 2606 ? 00:00:00 udisksd
2655 902 902 ? 00:00:02 fwupd
5946 5946 5946 ? 00:00:00 cupsd
5952 5952 5946 ? 00:00:00 dbus
9196 9196 5946 ? 00:00:00 dbus
5947 5947 5947 ? 00:00:00 cups-browsed
14433 14433 14433 ? 00:00:00 atd

You can also use the pstree command to achieve the same result of printing a process tree, type:

# pstree

Outputs:

devops@devops-osetc:~/working$ pstree
systemd─┬─ModemManager─┬─{gdbus}
│ └─{gmain}
├─NetworkManager─┬─dhclient
│ ├─dnsmasq
│ ├─{gdbus}
│ └─{gmain}
├─accounts-daemon─┬─{gdbus}
│ └─{gmain}
├─acpid
├─agetty
├─atd
├─avahi-daemon───avahi-daemon
├─colord─┬─{gdbus}
│ └─{gmain}
├─cron
├─cups-browsed─┬─{gdbus}
│ └─{gmain}
├─cupsd───2*[dbus]
├─dbus-daemon
├─fwupd─┬─3*[{GUsbEventThread}]
│ ├─{fwupd}
│ ├─{gdbus}
│ └─{gmain}
├─gnome-keyring-d─┬─{gdbus}
│ ├─{gmain}
│ └─{timer}
├─lightdm─┬─Xorg
│ ├─lightdm─┬─upstart─┬─at-spi-bus-laun─┬─dbus-daemon
│ │ │ │ ├─{dconf worker}
│ │ │ │ ├─{gdbus}
│ │ │ │ └─{gmain}

List All Running Process with Top COMMAND


You can use the top command to display a dynamic real-time view of a running system. It can display system summary information as well as a list of processes or threads currently being managed by the Linux kernel. Type:

# top

Outputs:

top - 03:31:16 up 1 day, 6:15, 2 users, load average: 0.24, 0.15, 0.10
Tasks: 188 total, 1 running, 187 sleeping, 0 stopped, 0 zombie
%Cpu(s): 16.3 us, 1.0 sy, 0.0 ni, 81.4 id, 1.0 wa, 0.0 hi, 0.3 si, 0.0 st
KiB Mem : 1015756 total, 154380 free, 522648 used, 338728 buff/cache
KiB Swap: 1046524 total, 765416 free, 281108 used. 314856 avail Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2544 devops 20 0 1156340 87036 12708 S 15.5 8.6 236:05.60 compiz
1033 root 20 0 306016 28160 7744 S 1.0 2.8 14:34.37 Xorg
1085 redis 20 0 40136 5432 1392 S 0.3 0.5 2:47.79 redis-server
2907 devops 20 0 94904 2088 1128 S 0.3 0.2 0:02.28 sshd
1 root 20 0 185248 4928 3268 S 0.0 0.5 0:04.67 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.02 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:04.62 ksoftirqd/0

Get Info about Threads


If you want to get detailed information about a threads in your system, you can type the following command:

# ps -eLf

Outputs:

devops@devops-osetc:~/working$ ps -eLf
UID PID PPID LWP C NLWP STIME TTY TIME CMD
redis 1085 1 1085 0 3 Dec18 ? 00:02:47 /usr/bin/redis-server 127.0.0.1:6379
redis 1085 1 1087 0 3 Dec18 ? 00:00:00 /usr/bin/redis-server 127.0.0.1:6379
redis 1085 1 1088 0 3 Dec18 ? 00:00:00 /usr/bin/redis-server 127.0.0.1:6379
root 1092 1 1092 0 1 Dec18 ? 00:00:00 /usr/sbin/sshd -D
root 1096 950 1096 0 1 Dec18 ? 00:00:00 /sbin/dhclient -d -q -sf /usr/lib/NetworkManager/nm-dhcp-helper -pf /var/run/dhclient-enp0s3.pi
nobody 1112 950 1112 0 1 Dec18 ? 00:00:01 /usr/sbin/dnsmasq --no-resolv --keep-in-foreground --no-hosts --bind-interfaces --pid-file=/var
root 1540 1017 1540 0 3 Dec18 ? 00:00:00 lightdm --session-child 12 19

Lookup Process based on Name


If you want to look up or signal processes based on name and other attributes, you can use pgrep command to lookup process through the currently running processes and lists the process IDs which match the selection criteria to stdout. All the criteria have to match.

For example,

$ pgrep -u root sshd

will only list the processes called sshd AND owned by root. On the other hand,

$ pgrep -u root,daemon

will list the processes owned by root OR daemon.

Outputs:

devops@devops-osetc:~/working$ pgrep -u root sshd
1092
2855
devops@devops-osetc:~/working$ pgrep -u root,daemon
1
2
3
5
7
8