• Home
  • LLMs
  • Docker
  • Kubernetes
  • Java
  • All
  • About
Linux-Ubuntu | ps -- List processes
  1. Notes
  2. Examples
  3. Command Help (man ps)

  1. Notes
    ps [-AaCcEefhjlMmrSTvwXx]
       [-O fmt | -o fmt]
       [-G gid [,gid...]]
       [-g grp [,grp...]]
       [-u uid [,uid...]]
       [-p pid [,pid...]]
       [-t tty [,tty...]] [-U user [,user...]]

    For the processes which have been selected for display, the default information to display includes:
    The process ID (PID), the controlling terminal (TTY), the CPU time the process has used, and the associated command.

    The ps command supports three different types of options:
    • Unix-style options: they are preceded by a dash character (-f, ...).
    • BSD-style options: they are not preceded by a dash character (x, ...).
    • GNU long options: they are preceded by a double dash characters (--forest, ...).

    Here's a list of some the headers that are displayed by the ps command:
    • UID: the user that started the process.
    • PID: the process ID.
    • PPID: the process ID of the parent of the process.
    • C: the utilization of the processor.
    • STIME: the system time when the process started.
    • TTY: the terminal that started the process.
    • TIME: the total time required to run the process.
    • CMD: the command that started the process.

    Extra headers can be shown with the option -l:
    • F: the system flags assigned to the process by the kernel.
    • S: the state of the process (O: running, S: sleeping, R: runnable, Z: zombie, T: stopped).
    • PRI: the priority of the process (lower numbers means higher priority).
    • NI: the nice value.
    • ADDR: the memory address of the process.
    • SZ: the swap space required by the process.
    • WCHAN: the address of the kernel where the process is sleeping.

    The BSD-style option l show a special header STAT that display the state of the process using two characters:
    • The first character shows the state of the process (O: running, S: sleeping, R: runnable, Z: zombie, T: stopped).
    • The second character shows the status of the process:
      • <: the process is running at high priority.
      • N: the process is running at low priority.
      • L: the process has pages locked in memory.
      • s: the process is a session leader.
      • l: the process is multi-threaded.
      • +: the process is running in the foreground.
  2. Examples
    • List processes that belongs to the current user and running on the current terminal:

      • Default output:
        $ ps
         PID TTY          TIME CMD
        5355 pts/0    00:00:00 bash
        7719 pts/0    00:00:00 ps

      • Full-format:
        $ ps -f
        UID        PID  PPID  C STIME TTY          TIME CMD
        mtitek    5355  5354  0 14:57 pts/0    00:00:00 -bash
        mtitek    7706  5355  0 18:51 pts/0    00:00:00 ps -f

      • Long format (Unix-style option):
        $ ps -l
        F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
        0 S  1000  5355  5354  0  80   0 -  5732 wait   pts/0    00:00:00 bash
        0 R  1000  7708  5355  0  80   0 -  7230 -      pts/0    00:00:00 ps

      • Long format (BSD-style option):
        $ ps l
        F   UID   PID  PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND
        0  1000  5355  5354  20   0  22928  5512 wait   Ss   pts/0      0:00 -bash
        0  1000  9642  5355  20   0  28920  1484 -      R+   pts/0      0:00 ps l

    • List processes that belongs to the current user including processes without a terminal device assigned:
      $ ps x
       PID TTY      STAT   TIME COMMAND
      5258 ?        Ss     0:00 /lib/systemd/systemd --user
      5259 ?        S      0:00 (sd-pam)
      5354 ?        R      0:00 sshd: mtitek@pts/0
      5355 pts/0    Ss     0:00 -bash
      7980 pts/0    R+     0:00 ps x

    • Display processes hierarchy (the relationship between processes is drawn using ASCII characters):
      $ ps x --forest
       PID TTY      STAT   TIME COMMAND
      5354 ?        S      0:00 sshd: mtitek@pts/0
      5355 pts/0    Ss     0:00  \_ -bash
      8128 pts/0    R+     0:00      \_ ps x --forest
      5258 ?        Ss     0:00 /lib/systemd/systemd --user
      5259 ?        S      0:00  \_ (sd-pam)

    • List all processes:
      $ ps -e

      $ ps -A

    • List PID processes:
      $ ps | grep bash | grep -v grep | awk '{print $1}'
      17190
      $ ps | grep bash | grep -v grep | awk {'print $1 " " $2 " " $3 " " $4 " " $5 '}
      17190 pts/0 00:00:00 bash

      $ ps | grep bash | grep -v grep | colrm 6
      17190

      $ for pid in `ps -e -f | grep mongodb | grep -v grep | awk '{print $2}'`; do echo "PID: $pid"; done
      PID: 19034

    • Kill processes:
      $ for pid in `ps -e -f | grep mongodb | grep -v grep | awk '{print $2}'`; do kill -9 $pid; done
  3. Command Help (man ps)
    Basic options:
    -A, -e               all processes
    -a                   all with tty, except session leaders
     a                   all with tty, including other users
    -d                   all except session leaders
    -N, --deselect       negate selection
     r                   only running processes
     T                   all processes on this terminal
     x                   processes without controlling ttys

    Selection by list:
    -C <command>         command name
    -G, --Group <GID>    real group id or name
    -g, --group <group>  session or effective group name
    -p, p, --pid <PID>   process id
           --ppid <PID>  parent process id
    -q, q, --quick-pid <PID> process id (quick mode)
    -s, --sid <session>  session id
    -t, t, --tty <tty>   terminal
    -u, U, --user <UID>  effective user id or name
    -U, --User <UID>     real user id or name

    The selection options take as their argument either:
    - a comma-separated list e.g. '-u root,nobody'
    - or a blank-separated list e.g. '-p 123 4567'

    Output formats:
    -F                   extra full
    -f                   full-format, including command lines
     f, --forest         ascii art process tree
    -H                   show process hierarchy
    -j                   jobs format
     j                   BSD job control format
    -l                   long format
     l                   BSD long format
    -M, Z                add security data (for SELinux)
    -O <format>          preloaded with default columns
     O <format>          as -O, with BSD personality
    -o, o, --format <format> user-defined format
     s                   signal format
     u                   user-oriented format
     v                   virtual memory format
     X                   register format
    -y                   do not show flags, show rss vs. addr (used with -l)
        --context        display security context (for SELinux)
        --headers        repeat header lines, one per page
        --no-headers     do not print header at all
        --cols, --columns, --width <num> set screen width
         --rows, --lines <num> set screen height

    Show threads:
     H                   as if they were processes
    -L                   possibly with LWP and NLWP columns
    -m, m                after processes
    -T                   possibly with SPID column

    Miscellaneous options:
    -c                   show scheduling class with -l option
     c                   show true command name
     e                   show the environment after command
     k,    --sort        specify sort order as: [+|-]key[,[+|-]key[,...]]
     L                   show format specifiers
     n                   display numeric uid and wchan
     S,    --cumulative  include some dead child process data
    -y                   do not show flags, show rss (only with -l)
    -V, V, --version     display version information and exit
    -w, w                unlimited output width
    
           --help <simple|list|output|threads|misc|all> display help and exit
© 2025  mtitek