Beginners Guide for PS Command in Linux

Linux TLDR
Last Updated:
Reading time: 6 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
Host System and ArchitectureUbuntu 22.10 (x64)
OS Compatibility Ubuntu, 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
    PID TTY          TIME CMD
   6846 pts/0    00:00:00 bash
   9583 pts/0    00:00:00 ps

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
    PID TTY          TIME CMD
      1 ?        00:00:09 systemd
      2 ?        00:00:00 kthreadd
      3 ?        00:00:00 rcu_gp
      4 ?        00:00:00 rcu_par_gp
      5 ?        00:00:00 netns

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

$ ps aux
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.1  0.1 166772 12020 ?        Ss   12:45   0:10 /sbin/init au
root           2  0.0  0.0      0     0 ?        S    12:45   0:00 [kthreadd]
root           3  0.0  0.0      0     0 ?        I<   12:45   0:00 [rcu_gp]
root           4  0.0  0.0      0     0 ?        I<   12:45   0:00 [rcu_par_gp]
root           5  0.0  0.0      0     0 ?        I<   12:45   0:00 [netns]

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

$ ps aux | grep nginx
root        2540  0.0  0.0   6268  4920 ?        S    12:45   0:00 nginx: master process nginx -g daemon off;
systemd+    2556  0.0  0.0   6916  4268 ?        S    12:45   0:01 nginx: worker process
systemd+    2557  0.0  0.0   6772  4212 ?        S    12:45   0:00 nginx: worker process
systemd+    2558  0.0  0.0   6756  1984 ?        S    12:45   0:00 nginx: worker process
systemd+    2559  0.0  0.0   6756  1984 ?        S    12:45   0:00 nginx: worker process

Use the “--no-header” flag to list the running process without a header.

$ ps --no-header
   6846 pts/0    00:00:00 bash
  34851 pts/0    00:00:00 ps

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
    PID TTY          TIME CMD
   5912 tty2     00:00:00 gnome-session-b
   6887 pts/1    00:00:00 man
   6908 pts/1    00:00:00 pager
  14628 pts/0    00:00:00 ps

Listing All Processes Except Session Leaders

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

$ ps -d
    PID TTY          TIME CMD
      2 ?        00:00:00 kthreadd
      3 ?        00:00:00 rcu_gp
      4 ?        00:00:00 rcu_par_gp
      5 ?        00:00:00 netns

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
UID          PID    PPID  C STIME TTY          TIME CMD
linuxtl+    5912    5909  0 12:49 tty2     00:00:00 /usr/libexec/gnome-session-b
linuxtl+   18045    6866  0 14:21 pts/1    00:00:00 man ps
linuxtl+   18053   18045  0 14:21 pts/1    00:00:00 pager
linuxtl+   19386    6846  0 14:32 pts/0    00:00:00 ps -af

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
    PID TTY          TIME CMD
      1 ?        00:00:10 systemd
      2 ?        00:00:00 kthreadd
      3 ?        00:00:00 rcu_gp
      4 ?        00:00:00 rcu_par_gp
      5 ?        00:00:00 netns

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
    PID TTY      STAT   TIME COMMAND
   6846 pts/0    Ss     0:00 bash
  17328 pts/0    R+     0:00 ps t

Listing Only the Running Processes Associated With the Current Terminal

The “r” or “-r” flag will only list the running processes associated with your current terminal.

$ ps r
    PID TTY      STAT   TIME COMMAND
  17428 pts/0    R+     0:00 ps r

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
    PID TTY      STAT   TIME COMMAND
   5811 ?        Ss     0:06 /lib/systemd/systemd --user
   5812 ?        S      0:00 (sd-pam)
   5819 ?        S<sl   0:00 /usr/bin/pipewire
   5820 ?        Ssl    0:00 /usr/bin/pipewire-media-session

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
UID          PID    PPID  C STIME TTY          TIME CMD
linuxtl+    5811       1  0 12:49 ?        00:00:07 /lib/systemd/systemd --user
linuxtl+    5812    5811  0 12:49 ?        00:00:00 (sd-pam)
linuxtl+    5819    5811  0 12:49 ?        00:00:00 /usr/bin/pipewire

Or

$ ps -fu 1003
UID          PID    PPID  C STIME TTY          TIME CMD
linuxtl+    5811       1  0 12:49 ?        00:00:07 /lib/systemd/systemd --user
linuxtl+    5812    5811  0 12:49 ?        00:00:00 (sd-pam)
linuxtl+    5819    5811  0 12:49 ?        00:00:00 /usr/bin/pipewire

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
    PID TTY          TIME CMD
      1 ?        00:00:12 systemd
      2 ?        00:00:00 kthreadd
      3 ?        00:00:00 rcu_gp
      4 ?        00:00:00 rcu_par_gp
      5 ?        00:00:00 netns

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
UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  0 12:45 ?        00:00:12 /sbin/init auto noprompt spl
root           2       0  0 12:45 ?        00:00:00 [kthreadd]
root           3       2  0 12:45 ?        00:00:00 [rcu_gp]
root           4       2  0 12:45 ?        00:00:00 [rcu_par_gp]
root           5       2  0 12:45 ?        00:00:00 [netns]
root           7       2  0 12:45 ?        00:00:00 [kworker/0:0H-events_highpri
root           9       2  0 12:45 ?        00:00:01 [kworker/0:1H-events_highpri
root          10       2  0 12:45 ?        00:00:00 [mm_percpu_wq]

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

$ ps -fg root
UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  0 12:45 ?        00:00:12 /sbin/init auto noprompt spl
root           2       0  0 12:45 ?        00:00:00 [kthreadd]
root           3       2  0 12:45 ?        00:00:00 [rcu_gp]
root           4       2  0 12:45 ?        00:00:00 [rcu_par_gp]
root           5       2  0 12:45 ?        00:00:00 [netns]
root           7       2  0 12:45 ?        00:00:00 [kworker/0:0H-events_highpri
root           9       2  0 12:45 ?        00:00:01 [kworker/0:1H-kblockd]
root          10       2  0 12:45 ?        00:00:00 [mm_percpu_wq]

Displaying Specific Process Information with PID or PPID

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

$ ps -fp 6846
UID          PID    PPID  C STIME TTY          TIME CMD
linuxtl+    6846    6820  0 12:50 pts/0    00:00:00 bash

Use the following command to specify PPID.

$ ps -f --ppid 6820
UID          PID    PPID  C STIME TTY          TIME CMD
linuxtl+    6846    6820  0 12:50 pts/0    00:00:00 bash

To list the group of processes with multiple PIDs.

$ ps -fp 6820,154,5
UID          PID    PPID  C STIME TTY          TIME CMD
root           5       2  0 12:45 ?        00:00:00 [netns]
root         154       2  0 12:45 ?        00:00:00 [ipv6_addrconf]
linuxtl+    6820    5811  0 12:50 ?        00:00:41 /usr/libexec/gnome-terminal-

Listing the Processes Based on TTY

Use the “-t” flag to list the processes based on tty.

$ ps -f -t pts/0
UID          PID    PPID  C STIME TTY          TIME CMD
linuxtl+    6846    6820  0 12:50 pts/0    00:00:00 bash
linuxtl+   22959    6846  0 15:02 pts/0    00:00:00 ps -f -t pts/0

Or

$ ps -f -t pts/1
UID          PID    PPID  C STIME TTY          TIME CMD
linuxtl+    6866    6820  0 12:50 pts/1    00:00:00 bash
linuxtl+   18045    6866  0 14:21 pts/1    00:00:00 man ps
linuxtl+   18053   18045  0 14:21 pts/1    00:00:00 pager

Or

$ ps -f -t tty2
UID          PID    PPID  C STIME TTY          TIME CMD
linuxtl+    5909    5743  0 12:49 tty2     00:00:00 /usr/libexec/gdm-wayland-ses
linuxtl+    5912    5909  0 12:49 tty2     00:00:00 /usr/libexec/gnome-session-b

ASCII Art Process Tree

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

$ ps -e --forest
    PID TTY          TIME CMD
      2 ?        00:00:00 kthreadd
      3 ?        00:00:00  \_ rcu_gp
   6812 ?        00:00:00  \_ gnome-terminal
   6815 ?        00:00:00  |   \_ gnome-terminal.
   6820 ?        00:00:43  \_ gnome-terminal-
   6846 pts/0    00:00:00  |   \_ bash
  23312 pts/0    00:00:00  |   |   \_ ps
   6866 pts/1    00:00:00  |   \_ bash
  23147 pts/1    00:00:00  |       \_ man
  23155 pts/1    00:00:00  |           \_ pager
   6859 ?        00:00:00  \_ gnome-terminal
   6861 ?        00:00:00      \_ gnome-terminal.

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

$ ps -e --forest | grep gnome-terminal
   6812 ?        00:00:00  \_ gnome-terminal
   6815 ?        00:00:00  |   \_ gnome-terminal.
   6820 ?        00:00:44  \_ gnome-terminal-
   6859 ?        00:00:00  \_ gnome-terminal
   6861 ?        00:00:00      \_ gnome-terminal.

Listing the Processes with Custom Output Format

Execute the following command with “L” to get the list of valid format specifiers.

$ ps L
cp           CP      
cpuid        CPUID   
cputime      TIME    
cputimes     TIME  

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
    PID    PPID USER     GROUP    CMD
      1       0 root     root     /sbin/init auto noprompt splash
      2       0 root     root     [kthreadd]
      3       2 root     root     [rcu_gp]
      4       2 root     root     [rcu_par_gp]
      5       2 root     root     [netns]

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
    PID TTY          TIME CMD
   2540 ?        00:00:00 nginx
   2556 ?        00:00:01 nginx
   2557 ?        00:00:00 nginx
   2558 ?        00:00:00 nginx
   2559 ?        00:00:00 nginx
  21648 ?        00:00:00 nginx
  21649 ?        00:00:00 nginx
  21650 ?        00:00:00 nginx
  21651 ?        00:00:00 nginx
  21652 ?        00:00:00 nginx

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.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.