Blog Dedicated Server Hosting

Top ps Command Examples to Monitor Your Linux Processes

Updated 4 min read

The ps command, also called “processes status,” is a tool to view information about running processes on a Linux-based operating system. It is used to monitor all running processes along with USER, PID, %CPU, %MEM, VSZ, RSS, TTY, STAT, and many more. The ps command is very useful, allowing system administrators to find the PID of any process to troubleshoot issues. It is one of the most powerful and essential process management tools that every Linux user should know and learn.

1. List All Processes of the Current User

You can use the ps command without any parameters to display a list of all running processes started by the user who ran the command.

ps

You should see the following output:

PID TTY TIME CMD
3871 pts/5 00:00:00 bash
5633 pts/5 00:00:00 ps

As you can see, there are four columns. A brief explanation of each column is shown below:

PID : Specifies the process ID of the process.

TTY : Specifies the name of the console the user logged in.

TIME : Specifies the amount of CPU processing time.

CMS : Specifies the command used to launch the process.

2. List Processes for All Users

You can list all processes started by all users using the following command:

ps -ef | less

or

ps ax | less

You should see all the processes in the following screen:

Terminal output of ps listing every process owned by all users with PID and TTY

3. List Processes by User

You can also filter the processes using the option -u followed by the username.

For example, to list all processes owned by www-data user, use the following command:

ps -f -u www-data

You should see the following screen:

Terminal output of ps -f -u www-data filtering processes owned by the www-data user

You can also specify multiple usernames using a comma.

For example, to list all processes owned by the www-data and root users, use the following command:

ps -f -u www-data,root

4. List Processes by Name or PID

To list the processes, by name use the -C option with search term.

For example, to list the processes of MySQL, run the following command:

ps -C mysqld

Or

ps -ef | grep mysql

You should see the following screen:

Terminal output of ps -C mysqld listing the running MySQL process by name

You can also list the processes by process id using the -p option.

ps -f -p 11560

You should see the Apache process in the following output:

UID PID PPID C STIME TTY TIME CMD
www-data 11560 11559 0 Jun12 ? 00:00:00 /usr/sbin/apache2 -k start

5. Sort Processes by CPU and Memory Usage

Sometimes you will need to find out processes that are consuming lots of CPU and Memory. In this case, you can sort the process list based on a specific field or parameter.

Run the following command to list the top 10 processes consuming most of the CPU and Memory:

ps aux --sort=-pcpu,+pmem | head -10

You should see the following screen:

Terminal output of ps sorted by CPU and memory usage showing the top processes

6. Display Processes in Realtime

You can also display the top CPU and Memory consuming processes using the watch command with ps:

watch -n 1 'ps -e -o pid,uname,cmd,pmem,pcpu --sort=-pmem,-pcpu | head -15'

You should see the following screen:

Terminal output of watch ps showing CPU and memory usage refreshing in real time

7. List the Process Tree

Some processes are forked out of parent processes. This can help you to figure out an issue or identify a particular process. You can use -e option with –forest to show how processes are linked in a Linux.

ps -e --forest

You should see the following screen:

Terminal output of ps -e --forest showing the parent and child process tree

8. Display Elapsed Time of Running Processes

You can find out how long the process has been running for using the -o option:

ps -e -o pid,comm,etime | less

You should see the following screen:

Terminal output of ps -o etime showing the elapsed running time of processes

Conclusion

In the above guide, you learned how to use the ps command to monitor Linux processes. Try using the ps command today on dedicated server hosting from Atlantic.Net!

Share

Written by

View all articles →

Ready to Deploy?

Launch secure, compliant, enterprise-grade infrastructure with confidence.