The most common way to list processes currently running on your system is to use the command ps (short for process status). This command has a lot of options that come in handy when troubleshooting your system. Used without any options, the ps command displays only processes that are started from the current shell:
To get information about all processes running on the system, use ps -A:
The most used options with ps are a, u and x. This displays all processes running for all users on your system, along with useful information such as the username of the process′ owner, CPU loads, the starting time of the process, the command that initiated the process, etc.
Get full access to CentOS Quick Start Guide and 60K+ other titles, with free 10-day trial of O'Reilly. There's also live online events, interactive content, certification prep materials, and more.
Introduction Each application you use or a command you run on your Linux system creates a process or task. As a system administrator, you will need to manage processes to ensure optimal system performance. In this tutorial, we will cover different Linux commands you can use to list and manage currently running processes.
Prerequisites
Processes in Linux start every time you launch an application or run a command. While each command creates one process, applications create and run multiple processes for different tasks. By default, each new process starts as a foreground process. This means it must finish before a new process can begin. Running processes in the background allows you to perform other tasks at the same time. To list currently running processes, use the ps, top, htop, and atop Linux commands. You can also combine the ps command with the pgrep command to identify individual processes. The ps Linux command creates a snapshot of currently running processes. Unlike the other commands on this list, ps presents the output as a static list, not updated in real time. The ps command uses the following syntax: ps [options]Frequently used ps command options include:
Note: Check the complete list of ps command options by using man ps. Running the ps command without any options produces an output similar to:
The default output includes the following categories:
Using the combination of a, u, and x options results in a more detailed output: ps aux
The new categories of the expanded output include:
To display the running processes in a hierarchical view, enter: ps -axjf
Note: When using more than one ps command option containing a dash symbol ("-"), you only need to use one dash symbol before listing the options. For instance, to use the ps command with the -e and -f options, type ps -ef. Filter the list of processes by user with: ps -U [real user ID or name] -u [effective user ID or name] uFor example, showing a list of processes started by the user called phoenixnap: ps -U phoenixnap -u phoenixnap u
The top command displays the list of running processes in the order of decreasing CPU usage. This means that the most resource-heavy processes appear at the top of the list:
The output of the top command updates in real time, with the three-second default refresh rate. The top command output contains the following categories:
While the top command is running, use the following options to interact with it or change the output format:
Note: Options for interacting with the top command are case-sensitive. Make sure you turn the Caps Lock off first. The htop command offers the same output as the top command but in an easier-to-understand and user-friendly way. Since most Linux distributions don't include this command, install it with: sudo apt install htopUsing the htop command provides the following output:
Use the following keys to interact with the htop command:
The atop command provides a more comprehensive overview of the running processes compared to the top command. Start by installing the atop command with: The atop command creates an output similar to:
The heading section of the command output provides an overview of system resources, including process and performance-related statistics and memory, disk, and network usage. The lower section lists currently running processes and contains the following categories:
Using the atop command with the following options changes the output format:
Use the following flags to interact with the atop command:
Using the pgrep command allows you to search for a specific process. The pgrep command uses the following syntax: pgrep [process name]For instance, use the following command to search for the firefox process: pgrep firefoxThe command output lists the PID of the process:
Using this PID with the ps command allows you to get more information on the process. In this example, using the PID 1439 provides information on the firefox process: ps -e | grep 1439
Conclusion After reading this tutorial, you should be able to use the ps, top, htop, and atop commands to list and manage running processes in Linux. Use the available command options to customize the output and command behavior. |