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
Description | PS (Process Status) |
Difficulty Level | Moderate |
Root or Sudo Privileges | No |
OS Compatibility | Ubuntu, Manjaro, Fedora, etc. |
Prerequisites | ps |
Internet Required | No |
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:
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:
Columns | Description |
---|---|
PID | It will display the unique process ID of the running command |
TTY | Terminal type that the user is logged into |
TIME | The amount of CPU utilization time used to run the process |
CMD | Command name |
The PS command supports three types of syntax styles:
Syntax | Description |
---|---|
UNIX | Might be grouped and preceded by a hyphen. |
BSD | Might be grouped but not preceded by a hyphen. |
GNU | Long 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.
IDs | Description |
---|---|
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:
Execute the following command to list all the active processes in BSD format:
$ ps aux
Output:
List only the specific process that matches a string used as an argument to the grep command.
$ ps aux | grep nginx
Output:
Use the “--no-header
” flag to list the running process without a header.
$ ps --no-header
Output:
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 All Processes Except Session Leaders
The “-d
” flag will list all the running processes except for the session leader processes.
$ ps -d
Output:
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 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 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 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 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:
Or
$ ps -fu 1003
Output:
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 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:
Execute the following command to list the processes owned by the effective group name (or session).
$ ps -fg root
Output:
Displaying Specific Process Information with PID or PPID
The following command will list the information for the specified process PID.
$ ps -fp 4995
Output:
Use the following command to specify PPID.
$ ps -f --ppid 1
Output:
Listing the Processes Based on TTY
Use the “-t
” flag to list the processes based on tty.
$ ps -f -t pts/0
Output:
Or
$ ps -f -t tty2
Output:
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:
Grep the name of the process to print the specific process tree.
$ ps -e --forest | grep gnome-terminal
Output:
Listing the Processes with Custom Output Format
Execute the following command with “L
” to get the list of valid format specifiers.
$ ps L
Output:
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 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:
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.