October 17, 2019
October 17, 2019
Need to view all running processes on your Linux server and discover which consumes your resources the most? Look no further, because, in this article, we’ll explain how to list Linux processes by using several common commands.
A process is the execution of a program. They can be launched when opening an application or when issuing a command through the command-line terminal.
A command can only generate a process. However, an application can run multiple processes for different tasks. For instance, Google Chrome will start a different process each time a new tab is opened.
Each Linux process is assigned a unique PID (process identification number). If there are no possible combinations left, the system can reuse old PIDs for newer processes.
A process can be initiated as a foreground or background process.
By default, all commands that run in the shell will start as foreground processes. As the process occupies the shell, you have to wait until it is finished before executing other commands.
If a command takes too long to complete, you can run it as a background process by adding an ampersand (&) at the end of the command so you can use the shell for other tasks.
Occasionally, processes may consume a lot of resources and need to be killed. Alternatively, times when you may want to change the priority level of a process, so the system will allocate more resources to it. Regardless of the case, all these tasks require you to do the same thing: listing the running processes on Linux.
There are several commands that you can use to list running processes: ps, top, and htop.
The ps (process statuses) command produces a snapshot of all running processes. Therefore, unlike the Windows task manager, the results are static.
When this command is used without any additional argument or option, it will return a list of running processes along with four crucial columns: the PID, terminal name (TTY), running time (TIME), and the name of the command that launches the process (CMD). You can use ps aux to get more in-depth information about your running processes. Here’s a breakdown of each argument:
If you want to list Linux processes in a hierarchical view, use the ps -axjf command. In this format, the shell will put child processes under their parent processes. Aside from those two options, here are some other common examples of the ps command that list running processes in Linux:
The top command is used to discover resource-hungry processes. This Linux command will sort the list by CPU usage, so the process which consumes the most resources will be placed at the top.
Unlike the ps command, the output of the top command is updated periodically. That means you’ll see real-time updates for CPU usage and running time. Once the shell returns the list, you can press the following keys to interact with it:
|k||Kills a process|
|M||Sorts the list by memory usage.|
|N||Sorts the list by PID.|
|r||Changes the priority of a process.|
|h||Displays the help window.|
|z||Displays running processes in colors.|
|d||Changes the refresh time interval.|
|c||Displays the absolute path of a process.|
|CTRL+C or q||Stops the top command.|
Keep in mind that the keys above are case sensitive, so be sure not to enable the caps lock.
Both the htop and top command display the same information when listing your Linux processes, but the former offers user-friendly features that are great for everyday process management.
First thing first, the htop command allows you to scroll vertically and horizontally. As such, you can see the complete list of your Linux processes along with their full command lines.
What’s more, the command allows you to use a mouse to select items, kill processes without inserting their PIDs, change the priority of multiple processes easily, and so on.
Unfortunately, most Linux distributions don’t have this command right out of the box, so you need to install it manually.
If you use Ubuntu, you can install htop by running the following command:
sudo apt-get install htop
Once installed, type htop, and you’ll get a list of all your Linux processes. Just like the previous command, htop also has several keyboard shortcuts:
|F9||To kill a process.|
|F8||Increase the priority of a process.|
|F7||Decrease the priority of a process.|
|F6||Sort processes by any column.|
|F5||Display processes in a tree view.|
|F4||Filter the processes by name.|
|F3||Search for a process.|
|F2||Open htop setup.|
|F1||Display the help menu.|
It is important to know how to list all running processes in your Linux operating system. The knowledge will be useful when you need to manage processes.
Let’s take a look once more at the three commands that you can use to list Linux processes:
Which command do you prefer? Share your thoughts in the comment section below!