ps Command in Linux for Viewing Process Information
ps Command in Linux lists running processes with details like Process ID, CPU usage, and command name. It works by reading data from the /proc directory and supports various options to filter or format process information for monitoring and management.
🤖AI Overview:
ps Command in Linux is a built-in tool used to display information about running processes. It shows details such as process ID, terminal, CPU time, and command name. The command reads data from the system to list active processes and supports various options to filter and format the output for user-specific needs.
How does the ps command work?
Simply put, the ps command in Linux lists process information. The “ps” phrase is the abbreviation of “Process Status.” The ps command retrieves the data from the /proc directory and translates them for the user.
The /proc directory is a filesystem that records and stores process and kernel information. The options, or flags, used in the ps command make it even more useful for advanced Linux users to filter information based on desired factors.
The Linux ps command’s syntax is as follows:
syntax:
ps [options]
The ps command options can be written in three forms, plus their mixes:
- UNIX: It’s necessary to put a dash (-) before the option in UNIX-formatted flags. Example:
ps -aux - BSD: There is no need to put a dash before the option in BSD-formatted flags. Example:
ps aux - GNU-formatted flags need two dashes and are used for long options. Example:
ps --ppid 1
Now, let’s dive into the world of the ps command’s use cases in Linux.
The ps command use cases in Linux
Generally, the ps command lists and displays all the running processes in the Linux kernel. So, we can say that its main functionality is to display process information, including the process’s unique ID (PID), the terminal or user associated with the process, and the command launching the process.
But its functionality is not limited to this list. We can gather other important information using the Linux ps command, too. Information like CPU usage time by the process, elapsed time, the starting date of the process, and so on.
Additionally, we will cover all types of columns in the ps command’s result further in this article. Thus, we split the use cases of the ps command with examples into the “Basic” and “Advanced” sections so you can review them smoothly.
- Basic Usage
This section will present the bare ps command, its basic options with examples, the result’s four basic columns, and what they mean. Note that we can use the ps command with or without options in Linux.
We start with the bare ps command in Linux with example:
1. Listing the processes related to the current shell
Using the bare ps command lists currently running processes in the shell.
ps

As you witness, we have four columns: PID, TTY, TIME, and CMD. You may wonder what these four abbreviations stand for.
- PID: PID is the short form of “Process ID”. Every running process has a specific ID to differentiate it from other processes.
- TTY: TTY stands for “Terminal Type”, demonstrating the terminal used to run the specified process.
- TIME: Time is about the time the process has utilized the CPU, not the amount of time the process has been running.
- CMD: This element shows the command used in launching the process.

2. Using Linux ps command to view all running processes
As mentioned, we can use the ps command with or without options. From now on, we will discuss the many types of options and arguments that can be added to the basic ps command.
Let’s start with viewing all running processes in ubuntu and other distributions. To do so, put “-A” or “-e” at the end of the command.
ps -A

ps -e

Note that the command is unrelated to any terminal session whenever TTY is a question mark.
3. Viewing terminal-related processes
If you want to view the processes that are associated with the terminal, simply run this command:
ps -T

- By running this command, we will no longer see a question mark in the TTY column.
- This command has two functionalities: one to issue terminal-related processes and the other to display the threads of a specific process (discussed further in the article.)
4. Display the processes not related to the terminal
To view all processes except session leaders and processes related to the terminal, run the Ubuntu ps command:
ps -a

A session leader is a process that starts other processes, e.g., bash. As you can see, unlike the ps command itself, the “ps -a” doesn’t show the bash process.
5. Listing all running processes with the command’s full name
To list all currently running processes with the command’s full name, type the command below, then hit the Enter button:
ps -ax

- Advanced Usage
From now on, we will discuss advanced options of the ps command in Linux ubuntu, CentOS and etc. So, before reading this part, ensure you have at least intermediate-level coding knowledge.
1. List all processes in BSD format
In case you want to list processes in BSD format, these ps commands can help:
ps -au
or
ps au
and
ps aux

In the picture above,
- %CPU: The CPU utilization of the process is shown in this column.
- %MEM: Shows the percentage of the process’s resident size to the physical memory on the machine.
- VSZ: VSZ shows the amount of virtual memory the process is consuming in KiB.
- RSS: This is the size of the physical memory that the process is using.
- STAT: This column is about the status of the process generated in codes.
- START: The START column shows the time or the date when the process has begun.
The 13 codes of the STAT column are as follows:
| Process State Codes | Meaning |
|---|---|
| D | uninterruptible sleep |
| I | Idle kernel thread |
| R | running, runnable or on run queue |
| S | interruptible sleep (waiting for an event to complete) |
| T | stopped by job control signal |
| t | stopped by debugger during the tracing |
| Z | defunct "zombie" process, terminated but not reaped by its parent |
| < | high-priority |
| N | low-priority |
| L | has pages locked into memory |
| s | is a session leader |
| 1 | is multi-threaded |
| + | is in the foreground process group |
2. Full format listing with Linux ps command
To perform a full format listing, run either of these commands:
ps -ef
ps -eF


In the ps command format of listing, the meaning of columns is as follows:
- UID shows the user running the process.
- PPID is the ID of the parent process.
- C is the CPU utilization of the process.
- STIME is equal to the START, displaying the time or date when the process took place.
- SZ is about virtual memory usage.
- PSR demonstrates the processor to which the process is currently assigned.
3. To filter processes in regard to user
We can use the -u option after the ps command ubuntu to filter processes according to the user.
ps -u username
For example:
ps -u root

4. To view the thread of a specified process
In order to filter the ps command’s results based on the threads of a particular process, all you need to do is to add one of the -L or -T options to the ps command followed by the PID:
ps -L PID
ps -T PID
Examples:
ps -L 77
ps -T 529

The LWP and SPID columns refer to the thread ID.
5. Showing all the processes run by the root user
In case you want to view the list of all the processes run by the root user, execute:
ps -U root -u root

6. Using the ps command in Linux to show group processes
To list all the processes run under a specific group, execute the ps command as below:
ps -fG group_name
or
ps -fG groupID
For instance :
ps -fG root

7. ps command in Linux to search for process PID
It’s a common thing not to know the PID of a process. To search for the PID of a process, run this command:
ps -C process_name
For example:
ps -C bash

As you can see, we have three bash processes running on this kernel, each with a unique PID. But the bare ps command in Linux only shows the one related to the current terminal ( PID: 220430.)
But the ps command with the -C option followed by the process name engulfs all processes, showing all three (bash processes) in this example ( PIDs: 219199 / 219658 / 220430.)
We can say the ps command with the -C option is an all-encompassing command to search for PID.
8. Using the PID to search for the process name
On the other hand, sometimes we know the PID but not the process name. Having the PID in hand, we can search for the process name by the ps command. Note that we can only search for the running processes whose names are listed below the CMD column.
ps -p PID -o comm=
For example:
ps -p 84 -o comm=

In the command above, “-p” option indicates PID, “-o” option refers to the output format, and “comm=” displays the command’s name column.
To check whether the result is correct, let’s search the PID by the command’s name:
ps -C kswapd0

As you can see, the PID of the “kswapd0” process is 84.
9. Listing processes in accordance with PID
Processes can be listed according to their PID with the ps command ubuntu:
ps -fp PID
For instance:
ps -fp 88

10. Display process hierarchy in a tree diagram
Generally, most of the processes are child processes of parent ones. Being aware of this relationship between processes can be useful. The Linux ps command below lists the processes named “bash.”
ps -f --forest -C bash

11. Displaying the child processes of a parent one
We can list all the child processes of a parent process. If you want to list all the child processes of the “systemd” process, run the following:
ps -o pid,uname,comm -C systemd

The first process (PID: 1) is the main systemd2 process, and the other (PID: 217424) is its child process. We also can list all the child processes of a child process with the PID.
To list the child processes of a child process, run:
ps --ppid PID no.
In systemd2 case, we should run:
ps --ppid 1

As seen in the photo, the child process of systemd2 (PID: 217424) is again listed by the later command (marked by a tiny star.)
12. List processes with specific columns
We can set the ps command in Linux to display results with the desired columns. For instance:
ps -e -o pid,uname
This command will list the processes with only PID and USER columns:

The -o option defines the output format.
13. Renaming columns in the ps command search result
The ps command in Linux can be used to rename columns. To do so, you can make your specific rename command according to the command below:
ps -e -o pid=Algeria,uname=America

In this example, first, we limited listing columns to PID and uname, then renamed them to “Algeria” and “America,” respectively. You can rename any column to any phrase this way.
14. ps command to display the elapsed time of every process
In order to know how long a process has been running on the system, run:
ps -e -o pid,comm,etime

“etime” phrase in the command refers to the Elapsed column.
15. Search for a specific process using the ps command with grep
You can use the grep command in Linux with the ps command if you need to search for a specific process. For instance:
ps -ef | grep systemd

Conclusion
The ps command in Linux is an indispensable utility for developers and system administrators aiming to manage and monitor processes effectively. Its flexibility in presenting both simple and detailed process information makes it suitable for a wide range of scenarios from quick inspections to in-depth system diagnostics.
Given its foundational role in Linux process management, understanding the ps command in Linux is a critical skill for any developer or system engineer working with Unix-like operating systems. Regular practice with various options and scenarios will deepen understanding and proficiency, ultimately leading to improved system oversight and operational efficiency.
FAQ
2. How do I list all running processes using the ps command in Linux?
To list all running processes, use the command 'ps -A' or 'ps -e'. This will display every process running on the system regardless of the terminal session.
3. What are the common options or formats available with the ps command in Linux?
The ps command supports three option formats: UNIX (requires a dash, e.g., ps -aux), BSD (no dash, e.g., ps aux), and GNU long options (two dashes, e.g., ps --ppid 1). These formats allow various filtering and display customizations.
4. How can I filter processes by user using the ps command?
You can filter processes by a specific user with the option 'ps -u username'. For example, 'ps -u root' will list all processes owned by the root user.
5. How do I display all threads of a specific process using the ps command in Linux?
To view the threads of a particular process, use either 'ps -L PID' or 'ps -T PID', where PID is the process ID. This shows detailed thread information including thread IDs.
6. How can I display process hierarchy or parent-child relationships with the ps command?
Use 'ps -f --forest -C process_name' to display the process hierarchy in a tree format. To see child processes of a parent, use 'ps --ppid PID', replacing PID with the parent's process ID.
7. How do I customize the output columns or rename columns when using the ps command?
The '-o' option allows selecting specific output columns, e.g., 'ps -e -o pid,uname'. Renaming columns is possible by specifying the new names after '=', for example, 'ps -e -o pid=ProcessID,uname=UserName'.
8. How can the ps command help in finding the PID or process name when one is unknown?
To find the PID by process name, use 'ps -C process_name'. Conversely, to find the process name by PID, use 'ps -p PID -o comm='.
9. What advanced options does the ps command provide for detailed process information?
Advanced options include full-format listing with 'ps -ef' or 'ps -eF', displaying CPU usage (%CPU), memory usage (%MEM), process status codes (STAT), start times (START), and processor assignment (PSR) for comprehensive monitoring.
10. Can I use the ps command combined with other Linux tools to search for specific processes?
Yes, combining ps with grep is common for searching processes, for example, 'ps -ef | grep process_name' filters the process list to match specific keywords efficiently.