top ad article

As a Linux user you need the understanding of how the kernel communicates with processes and and how processes communicate with each other to be able to troubleshoot issues. Each process in a Linux system is assigned a state upon its creation.

The ps utility can be used to query status of a process. It displays a header line, followed by lines containing information about all of your processes that have controlling terminals. If you run ps aux, you’ll get a list all users with extended user-oriented details. This includes the terminal from which processes are started. A ? sign in the TTY column represents that the process did not start from a terminal.

The Linux version of ps supports three option formats:

  • UNIX (POSIX) options – must be preceded by a dash
  • BSD options – must not include a dash
  • GNU long options – preceded by two dashes

Below are the key columns in ps command output:

ColumnExplanation
PIDShows the unique process ID
TIMEShows the total CPU time consumed by the process in hours:minutes:seconds format, since the start of the process.
%CPUShows the CPU usage during the previous second as the sum across all CPUs expressed as a percentage
RSSShows the non-swapped physical memory that a process consumes in kilobytes in the resident set size, RSS column.
%MEMShows the ratio of the process’ resident set size to the physical memory on the machine, expressed as a percentage

Examples of using ps to monitor processes in Linux.

List all processes with full details

The output below uses the UNIX options to list every process with full details:

$ ps -ef

Sample output:

UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  0  2020 ?        00:05:36 /usr/lib/systemd/systemd --switched-root --system --deserialize 17
root           2       0  0  2020 ?        00:00:01 [kthreadd]
root           3       2  0  2020 ?        00:00:00 [rcu_gp]
root           4       2  0  2020 ?        00:00:00 [rcu_par_gp]
root           6       2  0  2020 ?        00:00:00 [kworker/0:0H-kblockd]
root           8       2  0  2020 ?        00:00:00 [mm_percpu_wq]
root           9       2  0  2020 ?        00:00:17 [ksoftirqd/0]
root          10       2  0  2020 ?        00:06:31 [rcu_sched]
root          11       2  0  2020 ?        00:00:00 [migration/0]
root          12       2  0  2020 ?        00:00:01 [watchdog/0]
root          13       2  0  2020 ?        00:00:00 [cpuhp/0]
root          14       2  0  2020 ?        00:00:00 [cpuhp/1]
root          15       2  0  2020 ?        00:00:13 [watchdog/1]
root          16       2  0  2020 ?        00:00:00 [migration/1]
root          17       2  0  2020 ?        00:00:16 [ksoftirqd/1]
root          19       2  0  2020 ?        00:00:00 [kworker/1:0H-kblockd]
root          21       2  0  2020 ?        00:00:00 [kdevtmpfs]
root          22       2  0  2020 ?        00:00:00 [netns]
root          23       2  0  2020 ?        00:00:10 [kauditd]
root          25       2  0  2020 ?        00:00:01 [khungtaskd]
root          26       2  0  2020 ?        00:00:00 [oom_reaper]
root          27       2  0  2020 ?        00:00:00 [writeback]
root          28       2  0  2020 ?        00:00:00 [kcompactd0
....

List the process running by using name

We’ll run the following commands to display information about running processes with the name nginx

$ ps -p $(pidof nginx)
    PID TTY      STAT   TIME COMMAND
 957061 ?        Ss     0:00 nginx: master process /usr/sbin/nginx
 957062 ?        S      1:09 nginx: worker process
 957063 ?        S      0:03 nginx: worker process

List all processes sorted by memory usage in descending order

Run the command to show all running processes in a Linux/Unix system with the output sorted by memory usage.

$ ps aux --format pid,%mem,cmd --sort -%mem
    PID %MEM CMD
 983595 14.2 /usr/sbin/mariadbd
  15047  1.2 /usr/libexec/platform-python -s /usr/sbin/firewalld --nofork --nopid
    647  0.8 /usr/lib/systemd/systemd-journald
    828  0.8 /usr/libexec/platform-python -Es /usr/sbin/tuned -l -P
    949  0.6 /usr/sbin/rsyslogd -n
 957056  0.5 php-fpm: master process (/etc/php-fpm.conf
...

List all processes sorted by cpu usage in descending order

For CPU sorting use the command below.

$ ps ax --format pid,%cpu,cmd --sort -%cpu
    PID %CPU CMD
1007359  2.6 php-fpm: pool www
 983595  0.1 /usr/sbin/mariadbd
....

List processes owned by user / group

List processes owned by nginx user.

$ ps -fU nginx
UID          PID    PPID  C STIME TTY          TIME CMD
nginx     957062  957061  0 Feb10 ?        00:01:09 nginx: worker process
nginx     957063  957061  0 Feb10 ?        00:00:03 nginx: worker process
nginx    1007374  957056  3 22:35 ?        00:00:00 php-fpm: pool www

Process owned by mysql user:

$ ps -fU mysql
UID          PID    PPID  C STIME TTY          TIME CMD
mysql     983595       1  0 Feb13 ?        00:05:17 /usr/sbin/mariadbd

Processes owned by nginx group:

$ ps -fG nginx
UID          PID    PPID  C STIME TTY          TIME CMD
nginx     957062  957061  0 Feb10 ?        00:01:09 nginx: worker process
nginx     957063  957061  0 Feb10 ?        00:00:03 nginx: worker process
nginx    1007414  957056  3 22:37 ?        00:00:00 php-fpm: pool www

List process by pid

Pass the process ID to ps command:

$ ps -f 957062
UID          PID    PPID  C STIME TTY      STAT   TIME CMD
nginx     957062  957061  0 Feb10 ?        S      1:09 nginx: worker process

Show Process tree

Show how process are linked to each other:

$ ps -e --forest

Show every process running as root

Use the commands:

$ ps -U root -u root

Search for process ID from name

See below example

$  ps -C nginx
    PID TTY          TIME CMD
 957061 ?        00:00:00 nginx
 957062 ?        00:01:10 nginx
 957063 ?        00:00:03 nginx

Check detailed ps command to learn more about ps command, available options and much more.

Similar guides.

How To Install AnyDesk on MX Linux

How To Install VMware Tools on MX Linux

Previous articleChange the Lock Screen Look on Windows 10 Easily
Next articleCustomize Microsoft Management Console Easily on Windows 10

LEAVE A REPLY

Please enter your comment!
Please enter your name here