Inspect Running Processes with the ps aux Command

ps (process list) is a Linux and Unix utility for monitoring running processes on your server. This quickstart guide explains how system administrators use the ps aux command for process monitoring.

The ps command accepts:

The same option name with different notation might give you different results. So, make sure you are using the correct option name and notation while executing the ps command in your system.

Prerequisites

To get started,

About The Ps Aux Command

After you connect to your Linux server with SSH, execute the following command:

$ ps aux

You will see the output similar to the following:

USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.0  0.4 171192  9804 ?        Ss   Jul28  10:11 /sbin/init
root           2  0.0  0.0      0     0 ?        S    Jul28   0:00 [kthreadd]
root           3  0.0  0.0      0     0 ?        I<   Jul28   0:00 [rcu_gp]
root           4  0.0  0.0      0     0 ?        I<   Jul28   0:00 [rcu_par_gp]
root           6  0.0  0.0      0     0 ?        I<   Jul28   0:00 [kworker/0:0H-kblockd]
root           9  0.0  0.0      0     0 ?        I<   Jul28   0:00 [mm_percpu_wq]
root          10  0.0  0.0      0     0 ?        S    Jul28   0:24 [ksoftirqd/0]
root          11  0.0  0.0      0     0 ?        I    Jul28   8:47 [rcu_sched]
root          12  0.0  0.0      0     0 ?        S    Jul28   0:09 [migration/0]
root          13  0.0  0.0      0     0 ?        S    Jul28   0:00 [idle_inject/0]
...

A typical Linux system has a lot of processes running at any given time. So, you will see many processes even if your server is brand new. Here is the explanation of the command.

The output of this command will contain many columns containing important information about the processes. Here is the meaning of each column from the output.

Filter And Sort The Processes

Without any filtering, ps reports all the processes running on the machine. If you are looking for a specific process or a group of processes, you can pipe the output to another command for filtering. You can also use various ps options to modify the output. Here are a few examples.

Filter Processes With The Grep Command

The grep The command allows you to filter files and output. You can pipe the output of the ps aux command to the grep command and filter according to your requirements.

For example, the following command will filter all the lines containing php-fpm from the list of processes.

$ ps aux | grep 'php-fpm'

You can use multiple options in the grep command to further filter the processes. For example, append | wc -l to count the number of processes.

Sort Processes With --sort Option

You can use the --sort option in the ps command to sort the output by any column.

For example, the following command will sort the processes based on CPU usage.

$ ps aux --sort=-pcpu

Similarly, you can use --sort=-pmem to sort processes by memory usage. Note that the (-) sign before pcpu and pmem in the option stands for descending order. If you want to sort the processes in ascending order, use the (+) sign. For example, +pcpu or +pmem.

Conclusion

The ps The command is potent and provides many options to find and monitor processes in various ways. For example, you can use the --forest option at the end of the command to see the process tree in the output. Similarly, you can use the -o option to select the columns you want for output.

If you want to learn the ps command and all its options, go to the terminal and execute man ps. You’ll find the man page containing a detailed explanation about all the available options.