ps
(process list) is a Linux and Unix utility that allows you to monitor running processes on your server. This quickstart guide explains how the ps aux
command is used by system administrators for process monitoring.
The ps
command accepts:
-option_name
)--option_name
)option_name
)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.
To get started,
ps aux
commandAfter 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.
ps
command. Without any options, It will show you the processes running in your own terminal for logged-in users only.u
option will show you user oriented list of processes.x
option will also show you processes without the TTY or the terminal screen.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.
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.
The grep
command allows you to filter from files and outputs. You can pipe the output of ps aux
command to 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 grep command to further filter the processes. For example, append | wc -l
to count the number of processes.
--sort
optionYou can use the --sort
option in 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
.
The ps
command is potent and provides many options to find and monitor the 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 `-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.