Which command will list all the running processes along with the process ID?
The ps command is used for process related operations. In the above command, Show Here's an actual example: Honestly, it's difficult to remember the weird You can or top command and note the process ID and process name as desired. If you know the PID, you can simply use the grep command to filter the output and get the details on that PID:
But as illustrated by the image below, the output gives other details along with the process name. That's not an issue if you are manually reading it. However, if you have to use it in a script, it could be an issue. This is where the Bonus tip: Since we are talking about process name and PIDs, let me quickly show you the reverse method, i.e., to find PID from process name. There is a dedicated command called
So, you just learned how to find process name from its PID in Linux command line and you also learned to get the PID from the process name. If something isn't working right, or you just have any comments in general, feel free to leave any of it in the comments below. 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 0, 1, 2, and 3 Linux commands. You can also combine the 0 command with the 5 command to identify individual processes.List Running Processes in Linux by Using the ps CommandThe 0 Linux command creates a snapshot of currently running processes. Unlike the other commands on this list, 0 presents the output as a static list, not updated in real time.The 0 command uses the following syntax:
Frequently used ps command options include:
Note: Check the complete list of 0 command options by using 2.Running the 0 command without any options produces an output similar to:The default output includes the following categories:
Using the combination of 9, 8, and 0 options results in a more detailed output:
The new categories of the expanded output include:
To display the running processes in a hierarchical view, enter:
Note: When using more than one 0 command option containing a dash symbol ("-"), you only need to use one dash symbol before listing the options. For instance, to use the 0 command with the 9 and 0 options, type 1.Filter the list of processes by user with:
For example, showing a list of processes started by the user called phoenixnap:
List Running Processes in Linux by Using the top CommandThe 1 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 1 command updates in real time, with the three-second default refresh rate. The 1 command output contains the following categories:
While the 1 command is running, use the following options to interact with it or change the output format:
Note: Options for interacting with the 1 command are case-sensitive. Make sure you turn the Caps Lock off first.List Running Processes in Linux by Using the htop CommandThe 2 command offers the same output as the 1 command but in an easier-to-understand and user-friendly way.Since most Linux distributions don't include this command, install it with:
Using the 2 command provides the following output:Use the following keys to interact with the 2 command:
List Running Processes in Linux by Using the atop CommandThe 3 command provides a more comprehensive overview of the running processes compared to the 1 command. Start by installing the 3 command with:
The 3 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 3 command with the following options changes the output format:
Use the following flags to interact with the 3 command:
Find Process IDs Using the pgrep CommandUsing the 5 command allows you to search for a specific process. The 5 command uses the following syntax:
For instance, use the following command to search for the firefox process:
The command output lists the PID of the process: Using this PID with the 0 command allows you to get more information on the process. In this example, using the PID 1439 provides information on the firefox process:
Conclusion After reading this tutorial, you should be able to use the 0, 1, 2, and 3 commands to list and manage running processes in Linux. |