How to List All Processes in Linux

Last updated on September 4th, 2024 at 04:21 am

Often system administrators need to list all processes in Linux to find out which processes are running. They may also need other information such as if a user is running any process, or if a specific process is running. There are several ways to monitor the processes that are running on your Linux system. In this article, we will learn how to list all processes by name, user, PID. You can use it to list all processes in Ubuntu, CentOS, Fedora, Redhat, and other Linux systems

Why List Linux Processes

Every command or application starts at least one process in your Linux system. Over time, as you run more and more processes, your CPU and memory usage increases and your system slows down. If the process has bugs such as memory leaks, then they may consume unnecessarily high memory for their performance. Some may even continue to run even after they finish their tasks. Also, when multiple users are using your system, each user will add a set of processes and consequent work load to it. It is important to monitor processes run by a user to ensure they are not running any unauthorized processes, and also prevent them from hogging system resources. Therefore, it is important to regularly keep track of all processes that are running in your system.

How to List all Processes in Linux

Here are the steps to list all processes in Linux/Unix. There are various commands like ps, top, htop and pgrep to list all processes in Linux. We will use ps command to view processes since it is one of the most common and comprehensive commands for this purpose.

Open terminal and run the following command to display all processes in Linux.

$ ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0  24336  2284 ?        Ss   Sep01   0:02 /sbin/init
root         2  0.0  0.0      0     0 ?        S    Sep01   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    Sep01   0:00 [ksoftirqd/0]
root         4  0.0  0.0      0     0 ?        S    Sep01   0:00 [kworker/0:0]
...

In the above command,
a = show processes for all users
u = display the process’s user/owner
x = also show processes not attached to a terminal

The above command will list all running processes. Please note, ps command supports several options. Except a, u, x mentioned above, all other options need you to add a hyphen ‘-‘ before them.

Bonus Read : How to Search a File in Linux

1. List Linux processes by User

Here’s the command to list all processes by a specific user, say, john

$ ps -u john

OR

$ ps -U john

In the above command,
-u : Show all processes by RUID
-U : Display all processes by EUID

You can also use top or pgrep commands to list processes by user in Linux.

$ top -U john
$ pgrep -u john

Bonus Read : How to Create Zip and Unzip file in Linux

2. List Linux Processes by Name

Here’s the command to list all processes by a specific name, say, firefox

$ ps aux | grep firefox

In the above command, we pass the output of ps aux to grep command and search for string “firefox”.
You can also use pgrep command for this purpose. It searches the current running processes and lists PIDs of matching processes.

$ pgrep firefox

Bonus Read : How to Install Zip File in Linux

3. List Linux Processes by PID

Here’s the command to find all processes by a specific PID, say, 1234

$ ps -p 1234

or

$ ps aux | grep 1234

4. Using top and htop

You can also use top or htop commands to display all running processes in your system. Here is their syntax.

$ top
OR
$ htop

The top command displays a list of running processes in decreasing order of CPU usage. htop also provides similar output but in a more user-friendly manner.

Conclusion

In this article, we have learnt several simple ways to easily list Linux processes. Depending on your requirement, you can view processes by name, PID, user or some other attribute. It is important to regularly keep a track of all processes that are running on your system. This will help you identify any malicious or unexpected processes early and take action. It will also help you quickly identify processes that are overloading your system.

Ubiq makes it easy to visualize data in minutes, and monitor in real-time dashboards. Try it today!