Beginners Guide for PS Command in Linux

Linux TLDR
Last Updated:
Reading time: 4 minutes

The PS, a.k.a. β€œprocess status”, is a native command-line utility for UNIX-based systems to monitor the currently running processes in your system.

It reads the information from the virtual files in the /proc filesystem and gives the running processes information like memory consumption, CPU usage, PID, command name, etc.

The output of this command varies depending on the running processes and the parameter used to view the list of processes.

Tutorial Details

DescriptionPS (Process Status)
Difficulty LevelModerate
Root or Sudo PrivilegesNo
OS CompatibilityUbuntu, Manjaro, Fedora, etc.
Prerequisitesps
Internet RequiredNo

Syntax of the PS Command

The ps command takes only one argument as an option.

$ ps [OPTION]

It will list the running processes in your current shell without any arguments.

$ ps

Output:

Listing all running processes using ps command

Note that you always see the ps process in the output when you execute this command, as ps is also a process.

The PS command output column breakdown is as follows:

ColumnsDescription
PIDIt will display the unique process ID of the running command
TTYTerminal type that the user is logged into
TIMEThe amount of CPU utilization time used to run the process
CMDCommand name

The PS command supports three types of syntax styles:

SyntaxDescription
UNIXMight be grouped and preceded by a hyphen.
BSDMight be grouped but not preceded by a hyphen.
GNULong options and preceded by double hyphens.

In Linux, every process has several IDs associated with it that you must know before understanding the PS command.

IDsDescription
Process ID (PID)It is a temporary ID associated with the process when it is initialized, and once the process exits and the parent process retrieves the exit status, the PID is free to be reused by a new process.
Parent Process ID (PPID)At every execution of a program, the kernel creates a process that uses the fork() system call to load execution details in memory; this process is known as the β€œparent process,” which is responsible for creating the β€œchild process.” If the parent process exits before the child, then the child’s PPID is changed to another process (usually PID 1).
Process Group ID (PGID)The process group is used to manage processes in Linux that share PGIDs. If the PID is equal to the PGID, then this process is a process group leader.
Session ID (SID)If the PID is equal to the SID, then this process is the session leader.

The PGID (Process Group) and SID (Session ID) are ways to manage multiple related processes as a unit.

A group of multiple process groups might belong to the same session, and the same session might hold multiple process groups.

Listing All Running Processes in Your System

The β€œ-A” or β€œ-e” flag will list all the running processes in your Linux system in generic (Unix/Linux) format.

$ ps -A

Output:

Listing all running processes including daemons and system process using ps command

Execute the following command to list all the active processes in BSD format:

$ ps aux

Output:

Listing all running processes including daemons and system process using ps command in BSD format

List only the specific process that matches a string used as an argument to the grep command.

$ ps aux | grep nginx

Output:

Listing all running processes with nginx name using ps command

Use the β€œ--no-header” flag to list the running process without a header.

$ ps --no-header

Output:

Listing running processes without showing header using ps command

Listing the Processes Not Associated with the Terminal

The β€œ-a” flag will display all the running processes except for the session leaders and processes that are not associated with a terminal.

$ ps -a

Output:

Listing running processes not associated to terminal using ps command

Listing All Processes Except Session Leaders

The β€œ-d” flag will list all the running processes except for the session leader processes.

$ ps -d

Output:

Listing running processes except session leader using ps command

Listing All Processes with Full-Format Listings

The β€œ-f” or β€œ-F” flag can be combined with other options to add additional columns like β€œUID” or β€œPPIDβ€œ.

$ ps -af

Output:

Listing running processes in full format using ps command

Listing All Processes Except Those That Fulfill the Specified Conditions (Negates the Selection)

Using the β€œ-N” or β€œ--deselect” flag will list all the processes except those that are fulfilled by the specified conditions (the opposite of selection).

For example, if you specify β€œ-a” with β€œ-Nβ€œ, it will show you the opposite result that only includes the processes with both session leaders and processes not associated with a terminal.

$ ps -a -N

Output:

Listing opposite running processes to the specified option using ps command

Listing All Processes Associated With the Current Terminal

The β€œt” or β€œT” flag will list all the processes associated with your current terminal.

$ ps t

Output:

Listing running processes associated to current terminal using ps command

Listing Only the Processes Owned by You

The β€œx” or β€œ-x” flag will only list the processes owned by the current logged-in user.

$ ps x

Output:

Listing all process owned by current user using ps command

Listing Processes by Real or Effective User ID

Use the β€œ-U” flag to list the processes based on real user ID (RUID) or name, or use the β€œ-u” flag to list the processes based on effective user ID (EUID) or name, along with the β€œ-f” flag to print the additional columns.

$ ps -fU linuxtldr

Output:

Listing process with real user ID using ps command

Or

$ ps -fu 1003

Output:

Listing process with effective user ID using ps command

Listing All Processes Running as Root

The following command will list all the processes running as root in real or effective user format.

$ ps -U root -u root

Output:

Listing all process running with root privileges using ps command

Listing the Group of Processes (Real or Effective Group ID)

Execute the following command to get the list of processes owned by a specific group (real group ID or name).

$ ps -fG root

Output:

Listing all process owned by specific group using ps command

Execute the following command to list the processes owned by the effective group name (or session).

$ ps -fg root

Output:

Listing all process owned by specific effective group using ps command

Displaying Specific Process Information with PID or PPID

The following command will list the information for the specified process PID.

$ ps -fp 4995

Output:

Listing process with specific PID using ps command

Use the following command to specify PPID.

$ ps -f --ppid 1

Output:

Listing all process with specific PPID using ps command

Listing the Processes Based on TTY

Use the β€œ-t” flag to list the processes based on tty.

$ ps -f -t pts/0

Output:

Listing all process running on specific TTY using ps command

Or

$ ps -f -t tty2

Output:

Another example for listing all process running on specific TTY using ps command

ASCII Art Process Tree

Use the β€œ--forest” flag to display the list of processes linked to each other in ASCII art.

$ ps -e --forest

Output:

Listing all process in ascii tree format for readability using ps command

Grep the name of the process to print the specific process tree.

$ ps -e --forest | grep gnome-terminal

Output:

Listing specific process in ascii tree format for readability using ps command

Listing the Processes with Custom Output Format

Execute the following command with β€œL” to get the list of valid format specifiers.

$ ps L

Output:

Listing all output format valid for ps command

Use the β€œ-o” or β€œ--format” flag to list the running process in the above format.

The following command will list the running processes with their PID, PPID, username, group, and command.

$  ps -eo pid,ppid,user,group,cmd

Output:

Listing all process using custom format in ps command

Listing Parent and Child Processes

Use the β€œ-C” flag to list all the processes with the specified command name, including its child processes.

$ ps -C nginx

Output:

Listing all parent and its child process running for specified command name using ps command

That was the end of the PS command examples.

This command is very useful.

If any examples are missed that must be included in this article, let us know in the comment section.

Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.