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, -p PID provides the process ID and -o comm= asks it to output the command associated with the given PID.

Here's an actual example:

Which command will list all the running processes along with the process ID?

Honestly, it's difficult to remember the weird ps -p PID -o comm= syntax. And if that's the case, you may either look into the man page of ps command or use other ways of getting the details.

You can or top command and note the process ID and process name as desired.

Which command will list all the running processes along with the process ID?

If you know the PID, you can simply use the grep command to filter the output and get the details on that PID:

ps aux | grep PID

But as illustrated by the image below, the output gives other details along with the process name.

Which command will list all the running processes along with the process ID?

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 ps -p PID -o comm= is better.

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 pidof and you can use it like this if you know the exact process name:

pidof exact_process_name

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.

How to list running processes in Linux

Prerequisites

  • A system running Linux
  • An account with root or sudo privileges
  • Access to the terminal window/command line

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 aux
0,
ps aux
1,
ps aux
2, and
ps aux
3 Linux commands. You can also combine the
ps aux
0 command with the
ps aux
5 command to identify individual processes.

List Running Processes in Linux by Using the ps Command

The

ps aux
0 Linux command creates a snapshot of currently running processes. Unlike the other commands on this list,
ps aux
0 presents the output as a static list, not updated in real time.

The

ps aux
0 command uses the following syntax:

ps [options]

Frequently used ps command options include:

  • ps aux
    9: List all ruining processes for all users.
  • ps -axjf
    0: List all processes on the system.
  • ps -axjf
    1: List all processes except session leaders (instances where the process ID is the same as the session ID) and processes not associated with a terminal.
  • ps -axjf
    2: List all processes except session leaders.
  • ps -axjf
    3: List all processes except those that fulfill a user-defined condition.
  • ps -axjf
    4: Displays process hierarchy as ASCII art.
  • ps -axjf
    5: Displays output in the jobs format.
  • ps -axjf
    6: List all processes associated with this terminal.
  • ps -axjf
    7: Only list running processes.
  • ps -axjf
    8: Expand the output to include additional information, for example, CPU and memory usage.
  • ps -axjf
    9: Define a user whose processes you want to list.
  • ps -U [real user ID or name] -u [effective user ID or name] u
    0: Include processes without a TTY.

Note: Check the complete list of

ps aux
0 command options by using
ps -U [real user ID or name] -u [effective user ID or name] u
2.

Running the

ps aux
0 command without any options produces an output similar to:

Running the ps command without any options

The default output includes the following categories:

  • PID: Process identification number.
  • TTY: The type of terminal the process is running on.
  • TIME: Total amount of CPU usage.
  • CMD: The name of the command that started the process.

Using the combination of

ps aux
9,
ps -axjf
8, and
ps -U [real user ID or name] -u [effective user ID or name] u
0 options results in a more detailed output:

ps aux

Using the aux options to expand the output of the ps command

The new categories of the expanded output include:

  • USER: The name of the user running the process.
  • %CPU: The CPU usage percentage.
  • %MEM: The memory usage percentage.
  • VSZ: Total virtual memory used by the process, in kilobytes.
  • RSS: Resident set size, the portion of RAM occupied by the process.
  • STAT: The current process state.
  • START: The time the process was started.

To display the running processes in a hierarchical view, enter:

ps -axjf

Displaying the running processes as a hierarchy tree using the ps command

Note: When using more than one

ps aux
0 command option containing a dash symbol ("-"), you only need to use one dash symbol before listing the options. For instance, to use the
ps aux
0 command with the
ps -U [real user ID or name] -u [effective user ID or name] u
9 and
ps -U phoenixnap -u phoenixnap u
0 options, type
ps -U phoenixnap -u phoenixnap u
1.

Filter the list of processes by user with:

ps -U [real user ID or name] -u [effective user ID or name] u

For example, showing a list of processes started by the user called phoenixnap:

ps -U phoenixnap -u phoenixnap u

Filtering the ps command output by user

List Running Processes in Linux by Using the top Command

The

ps aux
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:

Linux top command output

The output of the

ps aux
1 command updates in real time, with the three-second default refresh rate. The
ps aux
1 command output contains the following categories:

  • PID: Process identification number.
  • USER: The name of the user running the process.
  • PR: The scheduling priority for the process.
  • NI: The nice value of the process, with negative numbers indicating higher priority.
  • VIRT: The virtual memory amount used by the process.
  • RES: The resident (physical) memory amount used by the process.
  • SHR: The total shared memory used by the process.
  • S: The status of the process - R (running) or S (sleeping).
  • %CPU: The percentage of CPU usage.
  • %MEM: The memory usage percentage.
  • TIME+: Total CPU usage amount.
  • COMMAND: The name of the command that started the process.

While the

ps aux
1 command is running, use the following options to interact with it or change the output format:

  • c: Display the absolute process path.
  • d: Change the output refresh rate to a user-defined value (in seconds).
  • h: Display the help window.
  • k: Kill a process by providing the PID.
  • M: Sort the list by memory usage.
  • N: Sort the list by PID.
  • r: Change the nice value (priority) of a process by providing the PID.
  • z: Change the output color to highlight running processes.
  • q: Quit the command interface.

Note: Options for interacting with the

ps aux
1 command are case-sensitive. Make sure you turn the Caps Lock off first.

List Running Processes in Linux by Using the htop Command

The

ps aux
2 command offers the same output as the
ps aux
1 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 htop

Using the

ps aux
2 command provides the following output:

Linux htop command output

Use the following keys to interact with the

ps aux
2 command:

  • Directional keys: Scroll the process list vertically and horizontally.
  • F1: Open the help window.
  • F2: Open the htop command setup.
  • F3: Search for a process by typing the name.
  • F4: Filter the process list by name.
  • F5: Switch between showing the process hierarchy as a sorted list or a tree.
  • F6: Sort processes by columns.
  • F7: Decrease the nice value (increase priority) of a process.
  • F8: Increase the nice value (decrease priority) of a process.
  • F9: Kill the selected process.
  • F10: Exit the command interface.

List Running Processes in Linux by Using the atop Command

The

ps aux
3 command provides a more comprehensive overview of the running processes compared to the
ps aux
1 command. Start by installing the
ps aux
3 command with:

sudo apt install atop

The

ps aux
3 command creates an output similar to:

Linux atop command output

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:

  • PID: Process identification number.
  • SYSCPU: The CPU usage by the process while system handling.
  • USRCPU: The CPU usage by the process while running in user mode.
  • VGROW: The amount of virtual memory the process has occupied since the last output update.
  • RGROW: The amount of physical memory the process has occupied since the last output update.
  • RUID: The real user ID of the user that started the process.
  • ST: The current process status.
  • EXC: The exit code after the process terminates.
  • THR: The number of threads the process is using.
  • S: The current status of the primary thread of the process.
  • CPUNR: The number of CPUs used by the process.
  • CPU: The CPU percentage used by the process.
  • CMD: The name of the command that started the process.

Using the

ps aux
3 command with the following options changes the output format:

  • ps -axjf
    1: Show active processes only.
  • sudo apt install htop
    7: Show command line per process.
  • ps -axjf
    2: Show disk information.
  • sudo apt install htop
    9: Show total values as average-per-second.
  • sudo apt install atop
    0: Show memory information.
  • sudo apt install atop
    1: Show network information.
  • sudo apt install atop
    2: Show process scheduling information.
  • sudo apt install atop
    3: Show the verbose output.
  • sudo apt install atop
    4: Show individual threads.

Use the following flags to interact with the

ps aux
3 command:

  • a: Sort by most active resources.
  • c: Sort by CPU consumption.
  • d: Sort by disk activity.
  • m: Sort by memory usage.
  • n: Sort by network activity.

Find Process IDs Using the pgrep Command

Using the

ps aux
5 command allows you to search for a specific process. The
ps aux
5 command uses the following syntax:

pgrep [process name]

For instance, use the following command to search for the firefox process:

pgrep firefox

The command output lists the PID of the process:

Using the pgrep command to find a process ID

Using this PID with the

ps aux
0 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

Searching for a process with the ps command and PID

Conclusion

After reading this tutorial, you should be able to use the

ps aux
0,
ps aux
1,
ps aux
2, and
ps aux
3 commands to list and manage running processes in Linux.