Inspect Running Processes with the ps aux Command
![Inspect Running Processes with the ps aux Command header image](https://docs.vultr.com/public/doc-assets/1437/b71af2ce914ff490.png)
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:
- Unix-like options (
-option_name
) - GNU-like options (
--option_name
) - BSD-like options (
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.
Prerequisites
To get started,
- Create a new Linux cloud server at Vultr
- Access your Linux server with SSH
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.
- ps: The main
ps
command. Without any options, It will show you the processes running in your own terminal for logged-in users only. - a: The `a' option is used to get a list of all the processes with a terminal.
- u: The
u
option will show you user oriented list of processes. - x: The
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.
- USER: This column will show you the users owning the processes.
- PID: The process id of a specific process in table.
- %CPU: The CPU usage of each process at a specific time.
- %RAM: The RAM usage of each process at a specific time.
- VSZ: VSZ stands for virtual memory size. This column will display the virtual memory of each process running on the system.
- RSS: RSS stands for Resident Set Size. It will show you the physical memory allocated for a process.
- TTY: The TTY column shows us the terminal screen of the processes. If a process does not have the terminal screen, It will display '?'.
- STAT: The STAT column will show you the current status of the process. The most common status for any process is either sleeping(S) or running(R).
- START: This column will show you the start date and time of a specific process.
- TIME: This column will show you the CPU time duration utilized by a specific process.
- COMMAND: This column will show you the command that was used to spawn a specific process.
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 grep command
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 Processes with --sort
option
You 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
.
Conclusion
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.