Chapter 20. System Monitoring Tools

In order to configure the system, system administrators often need to determine the amount of free memory, how much free disk space is available, how the hard drive is partitioned, or what processes are running.

20.1. Viewing System Processes

20.1.1. Using the ps Command

The ps command allows you to display information about running processes. It produces a static list, that is, a snapshot of what is running when you execute the command. If you want a constantly updated list of running processes, use the top command or the System Monitor application instead.
To list all processes that are currently running on the system including processes owned by other users, type the following at a shell prompt:
ps ax
For each listed process, the ps ax command displays the process ID (PID), the terminal that is associated with it (TTY), the current status (STAT), the cumulated CPU time (TIME), and the name of the executable file (COMMAND). For example:
~]$ ps ax
PID TTY      STAT   TIME COMMAND
  1 ?        Ss     0:01 /usr/lib/systemd/systemd --switched-root --system --deserialize 23
  2 ?        S      0:00 [kthreadd]
  3 ?        S      0:00 [ksoftirqd/0]
  5 ?        S>     0:00 [kworker/0:0H]
[output truncated]
To display the owner alongside each process, use the following command:
ps aux
Apart from the information provided by the ps ax command, ps aux displays the effective user name of the process owner (USER), the percentage of the CPU (%CPU) and memory (%MEM) usage, the virtual memory size in kilobytes (VSZ), the non-swapped physical memory size in kilobytes (RSS), and the time or date the process was started. For example:
~]$ ps aux
USER  PID %CPU %MEM    VSZ   RSS TTY   STAT START   TIME COMMAND
root    1  0.3  0.3 134776  6840 ?     Ss   09:28   0:01 /usr/lib/systemd/systemd --switched-root --system --d
root    2  0.0  0.0      0     0 ?     S    09:28   0:00 [kthreadd]
root    3  0.0  0.0      0     0 ?     S    09:28   0:00 [ksoftirqd/0]
root    5  0.0  0.0      0     0 ?     S>   09:28   0:00 [kworker/0:0H]
[output truncated]
You can also use the ps command in a combination with grep to see if a particular process is running. For example, to determine if Emacs is running, type:
~]$ ps ax | grep emacs
12056 pts/3    S+     0:00 emacs
12060 pts/2    S+     0:00 grep --color=auto emacs
For a complete list of available command line options, see the ps(1) manual page.

20.1.2. Using the top Command

The top command displays a real-time list of processes that are running on the system. It also displays additional information about the system uptime, current CPU and memory usage, or total number of running processes, and allows you to perform actions such as sorting the list or killing a process.
To run the top command, type the following at a shell prompt:
top
For each listed process, the top command displays the process ID (PID), the effective user name of the process owner (USER), the priority (PR), the nice value (NI), the amount of virtual memory the process uses (VIRT), the amount of non-swapped physical memory the process uses (RES), the amount of shared memory the process uses (SHR), the process status field S), the percentage of the CPU (%CPU) and memory (%MEM) usage, the cumulated CPU time (TIME+), and the name of the executable file (COMMAND). For example:
~]$ top
top - 16:42:12 up 13 min,  2 users,  load average: 0.67, 0.31, 0.19
Tasks: 165 total,   2 running, 163 sleeping,   0 stopped,   0 zombie
%Cpu(s): 37.5 us,  3.0 sy,  0.0 ni, 59.5 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  1016800 total,    77368 free,   728936 used,   210496 buff/cache
KiB Swap:   839676 total,   776796 free,    62880 used.   122628 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
 3168 sjw       20   0 1454628 143240  15016 S 20.3 14.1   0:22.53 gnome-shell
 4006 sjw       20   0 1367832 298876  27856 S 13.0 29.4   0:15.58 firefox
 1683 root      20   0  242204  50464   4268 S  6.0  5.0   0:07.76 Xorg
 4125 sjw       20   0  555148  19820  12644 S  1.3  1.9   0:00.48 gnome-terminal-
   10 root      20   0       0      0      0 S  0.3  0.0   0:00.39 rcu_sched
 3091 sjw       20   0   37000   1468    904 S  0.3  0.1   0:00.31 dbus-daemon
 3096 sjw       20   0  129688   2164   1492 S  0.3  0.2   0:00.14 at-spi2-registr
 3925 root      20   0       0      0      0 S  0.3  0.0   0:00.05 kworker/0:0
    1 root      20   0  126568   3884   1052 S  0.0  0.4   0:01.61 systemd
    2 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kthreadd
    3 root      20   0       0      0      0 S  0.0  0.0   0:00.00 ksoftirqd/0
    6 root      20   0       0      0      0 S  0.0  0.0   0:00.07 kworker/u2:0
[output truncated]
Table 20.1, “Interactive top commands” contains useful interactive commands that you can use with top. For more information, see the top(1) manual page.

Table 20.1. Interactive top commands

Command Description
Enter, Space Immediately refreshes the display.
h Displays a help screen for interactive commands.
h, ? Displays a help screen for windows and field groups.
k Kills a process. You are prompted for the process ID and the signal to send to it.
n Changes the number of displayed processes. You are prompted to enter the number.
u Sorts the list by user.
M Sorts the list by memory usage.
P Sorts the list by CPU usage.
q Terminates the utility and returns to the shell prompt.

20.1.3. Using the System Monitor Tool

The Processes tab of the System Monitor tool allows you to view, search for, change the priority of, and kill processes from the graphical user interface.
To start the System Monitor tool from the command line, type gnome-system-monitor at a shell prompt. The System Monitor tool appears. Alternatively, if using the GNOME desktop, press the Super key to enter the Activities Overview, type System Monitor and then press Enter. The System Monitor tool appears. The Super key appears in a variety of guises, depending on the keyboard and other hardware, but often as either the Windows or Command key, and typically to the left of the Spacebar.
Click the Processes tab to view the list of running processes.
System Monitor — Processes

Figure 20.1. System Monitor — Processes

For each listed process, the System Monitor tool displays its name (Process Name), current status (Status), percentage of the CPU usage (% CPU), nice value (Nice), process ID (ID), memory usage (Memory), the channel the process is waiting in (Waiting Channel), and additional details about the session (Session). To sort the information by a specific column in ascending order, click the name of that column. Click the name of the column again to toggle the sort between ascending and descending order.
By default, the System Monitor tool displays a list of processes that are owned by the current user. Selecting various options from the View menu allows you to:
  • view only active processes,
  • view all processes,
  • view your processes,
  • view process dependencies,
Additionally, two buttons enable you to:
  • refresh the list of processes,
  • end a process by selecting it from the list and then clicking the End Process button.