
ps Command in Linux
The ps command in Linux displays information about currently running processes. It provides details such as process IDs (PIDs), CPU and memory usage, and execution time. This information helps with administrative tasks like setting process priorities.
The ps command supports three types of options: Unix-style (preceded by a dash), BSD-style (without a dash), and GNU long options (preceded by two dashes).
Table of Contents
Here is a comprehensive guide to the options available with the ps command â
Syntax of ps Command
The syntax of the ps command in Linux is as follows −
ps [optionsâ¦]
In the above syntax, the [optionsâ¦] field is used to specify options to change the commandâs output.
ps Command Options
The options for the Linux ps command are listed below −
Flag | Option | Description |
---|---|---|
-A, -e | Selects all processes except session leaders. | |
-a | Selects all except session leaders and processes without a terminal. | |
-d | Selects all except session leaders. | |
--deselect | Selects all except those matching specified conditions. | |
T | Selects all processes associated with the current terminal. | |
r | Restricts selection to running processes. | |
x | Lifts BSD-style restrictions, listing all user-owned or all processes with -a. | |
--help | Prints a help message. The section argument can be one of simple, list, output, threads, misc, or all, and can be abbreviated to one of the underlined letters (s, l, o, t, m, a). | |
--info | Prints debugging information. | |
L | Lists all format specifiers. | |
V, -V | --version | Prints the procps-ng version. |
Options for process selection by list are listed below −
Flag | Options | Description |
---|---|---|
-C cmdlist | Select by command name. | |
-G grplist | --Group grplist | Select by real group ID (RGID) or name. |
-g grplist | --group grplist | Select by session or effective group name. |
p pidlist, -p pidlist | --pid pidlist | Select by process ID. |
--ppid pidlist | Select by parent process ID. | |
q pidlist, -q pidlist | --quick-pid pidlist | Select by process ID (quick mode). |
-s sesslist | --sid sesslist | Select by session ID. |
t ttylist, -t ttylist | --tty ttylist | Select by terminal. |
-u userlist | --user userlist | Select by effective user ID (EUID) or name. |
-U userlist | --User userlist | Select by real user ID (RUID) or name. |
Options to change the output format are given below −
Flag | Option | Description |
---|---|---|
-c | Show different scheduler information for the -l option. | |
--context | Display security context format (for SELinux). | |
-f | Do full-format listing, adding additional columns and command arguments. | |
-F | Extra full format; implies -f. | |
o format, -o format | --format format | User-defined format for specifying output columns. |
j, -j | Display job control format. | |
l, -l | Display long format (BSD or standard). | |
M, Z | Add a column of security data (SELinux). | |
O format, -O format | User-defined output format with predefined common fields. | |
-P | Add a column showing processor (psr). | |
s | Display signal format. | |
u | Display user-oriented format. | |
v | Display virtual memory format. | |
X | Display register format. | |
-y | Show RSS in place of address, used with -l. | |
c | Show the true command name based on the executable file. | |
--cols n, --columns n, --width n | Set screen width. | |
--cumulative | Include some dead child process data with the parent. | |
-D format | --date-format format | Set the date format of the lstart field. |
E | Show the environment after the command. | |
f | --forest | ASCII art process hierarchy. |
H | No header (or one per screen in BSD mode). | |
-H | Show process hierarchy. | |
--headers | Repeat header lines on each page. | |
k spec | --sort spec | Specify sorting order. |
--lines n | --rows n | Set screen height. |
n | Numeric output for WCHAN and USER. | |
--no-headers | Print no header line. | |
O order | Sorting order (overloaded). | |
--signames | Show signal masks using abbreviated signal names. | |
w, -w | Wide output; use twice for unlimited width. |
To display the process threads, use the options listed below −
Option | Description |
---|---|
H | Displays threads as if they were separate processes. |
-L | Shows threads, possibly including LWP (Lightweight Process) and NLWP (Number of Lightweight Processes) columns. |
m, -m | Displays threads after processes. |
-T | Displays threads, possibly including the SPID (Thread ID) column. |
Examples of ps Command in Linux
This section discusses how to use the ps command in Linux to display the process details with examples −
- Displaying All Processes
- Displaying All Processes in BSD Format
- Displaying All Processes with Additional Details
- Displaying All Processes by Username
- Displaying Processes in Tree Format
- Displaying a Process with a Specific PID
- Displaying a Process by the Command Name
- Displaying Processes with User-defined Columns
- Displaying Threads
- Renaming Column Names
- Displaying Output without Headers
- Displaying Usage Help
Displaying All Processes
To display processes running in the current terminal, use the ps command without any option −
ps

To display all the processes currently running in the system, use the -A or -e option with the ps command −
ps -A

Or −
ps -e
In the output, a ? in the TTY column means the process is not linked to any terminal. This applies to system processes or background tasks that do not interact with a terminal.
Displaying All Processes in BSD Format
To display all processes in BSD format, use the ps command in the following way −
ps au

Or, use the following command for additional information −
ps aux

Displaying All Processes with Additional Details
To display all the processes currently running in the system with additional details, use the -f option. It shows a full-format listing, including columns like PPID, STIME, TIME, CMD, and UID.
ps -ef

Displaying All Processes by Username
To display all processes of a specific user, use the -u or --user option −
ps -u sam
Displaying Processes in Tree Format
To display all processes in the tree format, use the f or --forest option −
ps --forest
For all processes −
ps -e --forest

Displaying a Process with a Specific PID
To display a process with a specific PID, use the -p or --pid option −
ps -p 2552

Displaying a Process by the Command Name
To display a process by the command name, use the -C option −
ps -C vim

Displaying Processes with User-defined Columns
To display all the processes with the user-defined columns, use the o, -o, or --format option with the ps command −
ps -eo pid,comm,%cpu,%mem

In the above command -e is used to select all processes.
Displaying Threads
To display threads as processes, use the H option −
ps H
To display threads after the process in the output, use the m or -m option −
ps -m
The above command displays the process and thread of the process running in the current terminal session.
Renaming Column Names
To rename the column names of the output, use the following command −
ps -e -o pid=PID,uname=USERNAME,pcpu=CPU,pmem=%MEM,comm=COMMAND

Displaying Output without Headers
To display output without headers, use the --no-headers option −
ps --no-headers

Displaying Usage Help
To display usage help for the ps command, use the --help option −
ps --help
To display the debugging information, use the --info option −
ps --info
Conclusion
The ps command in Linux is a powerful tool for displaying information about running processes, such as process IDs, CPU and memory usage, and execution time. It offers various options for filtering, sorting, and formatting the output to meet specific needs. By using different flags and arguments, processes can be displayed in various formats, including by user, command name, or process ID.
Moreover, the ps command can show threads, rename output columns, and display detailed process information, making it an essential tool for system administrators and users monitoring system activity.