Website Vidya
Linux & ServersStep-by-Step Guide

ps Command in Linux: ps aux, ps -ef, Custom Columns, and Sorting

Learn ps command in linux with syntax, essential flags, practical terminal examples, real-world sysadmin workflows, security tips, and troubleshooting.

RR
Rajesh RayLead Systems Educator
Published:
11 min read
PDF Cheat Sheet
ps Command in Linux: ps aux, ps -ef, Custom Columns, and Sorting
AI Executive SummaryWebsiteVidya AI

11 min read

Learn ps command in linux with syntax, essential flags, practical terminal examples, real-world sysadmin workflows, security tips, and troubleshooting.

Key Highlights
  • What ps Does and When to Use It
  • Availability and Installation Across Linux Distributions
  • Command Syntax, Arguments, and Exit Status Codes
Grounded in full engineering runbookWebsiteVidya AI Engine

The ps command in linux (short for process status) is the foundational tool for inspecting running processes, threads, resource consumption, and parent-child hierarchies. Unlike interactive monitors such as top or htop that continuously refresh the terminal screen, ps outputs a clean, point-in-time table that can be filtered, sorted, piped into awk, or archived in incident-response logs.

What often surprises Linux newcomers is that ps supports three distinct option styles simultaneously: traditional UNIX / System V options preceded by a single dash (such as ps -ef), BSD options written without a leading dash (such as ps aux), and GNU long options preceded by two dashes (such as ps --sort=-%cpu). Because ps a and ps -a mean different things, knowing which syntax family you are using is crucial.

Beyond listing everything with ps aux or ps -ef, mastering custom output format specifiers (-o) and sorting keys (--sort) lets you pinpoint zombie tasks, uninterruptible disk-wait bottlenecks, kernel wait channels (wchan), Linux cgroup slices, and top memory consumers in milliseconds.

Advertisement
ps Command in Linux: ps aux, ps -ef, Custom Columns, and Sorting — syntax, flags, and practical terminal workflow diagram
ps Command in Linux: ps aux, ps -ef, Custom Columns, and Sorting — command syntax, key options, and production workflow reference.

What ps Does and When to Use It

Every time you run ps, the binary traverses the virtual /proc/[0-9]* directories exposed by the Linux kernel in RAM. For each process, it parses /proc/PID/stat (PID, PPID, process state, CPU jiffies, priority, nice value, RSS pages), /proc/PID/status (real and effective UIDs/GIDs, VmSize, VmRSS), and /proc/PID/cmdline (full command arguments). It never queries a central daemon, which means ps works reliably even if systemd or D-Bus is wedged.

Understanding the STAT column in ps aux is essential for kernel-level troubleshooting. The primary state characters are: R (Running or runnable on CPU run queue), S (Interruptible sleep, waiting for an event or socket I/O), D (Uninterruptible sleep, blocked in kernel space typically on disk or NFS I/O), T (Stopped by job control signal or trace), and Z (Defunct/zombie process terminated but not yet reaped by its parent). Trailing modifier characters indicate attributes like < (high-priority), N (low-priority nice), s (session leader), l (multi-threaded), and + (in the foreground process group).

Under the hood, ps gathers runtime telemetry or dispatches control signals by reading virtual filesystems mounted at /proc and /sys, or by communicating with PID 1 (systemd) over D-Bus. Using flags such as aux, -ef, -o, --sort turns raw process and service tables into actionable diagnostics during incident response.

Availability and Installation Across Linux Distributions

The ps utility is packaged in procps across mainstream Linux distributions. It is pre-installed on standard Ubuntu, Debian, RHEL, Rocky Linux, AlmaLinux, Fedora, and Arch Linux systems, while minimal container images may require manual installation:

Advertisement

Before running administrative tasks or automation scripts, verify whether ps is installed and inspect which binary path and version your shell resolves:

type -a ps
ps --version 2>/dev/null || man -f ps

# Illustrative output (reviewed against documentation)
ps is /usr/bin/ps
ps (procps)
# Debian / Ubuntu
sudo apt-get update && sudo apt-get install -y procps

# RHEL / Rocky / AlmaLinux / Fedora
sudo dnf install -y procps-ng

# Arch Linux
sudo pacman -S --noconfirm procps-ng

# Alpine Linux
sudo apk add --no-cache procps-ng

Command Syntax, Arguments, and Exit Status Codes

ps [UNIX_OPTIONS] | ps [BSD_OPTIONS] | ps [GNU_LONG_OPTIONS]

When you run ps with no arguments at all, it displays only processes belonging to the current user and attached to the current controlling terminal (TTY). To view every process on the machine using UNIX syntax, run ps -ef (or ps -ely): -e selects all processes and -f enables full-format listing including UID, PID, PPID, C, STIME, TTY, TIME, and CMD.

To view every process using BSD syntax (no leading hyphen), run ps aux: a lifts the 'only yourself' restriction for terminal processes, u selects user-oriented format (adding %CPU, %MEM, VSZ, RSS, and STAT columns), and x lifts the 'must have a tty' restriction so background daemons are included.

  • 0 — Successful execution with no runtime or permission errors.
  • 1 — Operational failure, unmatched condition, or permission restriction.
  • 2 — Invalid command-line option or malformed syntax.

Important Options and Flags Reference

Option / FlagLong Form / ArgumentTechnical Behavior and Purpose
aux(BSD style, no dash)Displays all processes on the system in user-oriented format including %CPU, %MEM, VSZ, RSS, and STAT columns.
-ef-e -f (UNIX style)Displays all processes on the system in full UNIX format, including Parent Process ID (PPID) and full command arguments.
-o--format FORMATPrints only user-specified columns (e.g., -o pid,ppid,user,%cpu,%mem,rss,stat,comm,args). Use = after a column name to suppress its header.
--sort--sort=[+|-]KEYSorts output by the specified column key; prefix with '-' for descending order (e.g., --sort=-%mem or --sort=-%cpu).
-u--user USERLISTFilters output to processes running under the specified effective username or UID (when preceded by a hyphen).
-CcmdlistSelects processes by exact executable command name (e.g., ps -C nginx -o pid,stat,args).
-p--pid PIDLISTSelects only the processes matching the comma-separated list of PIDs (e.g., ps -p 1104,29410).
--forest-H / f (BSD)Renders an ASCII art process tree showing parent-child hierarchy alongside process details.
-L-TDisplays individual Light-Weight Processes (threads / TIDs) within multi-threaded applications.

Why do administrators use both ps aux and ps -ef? Each default layout shows one crucial piece of data the other omits: ps aux includes %CPU, %MEM, RSS (resident memory in KiB), and the detailed STAT code, whereas ps -ef includes the PPID (Parent Process ID) column. You can get the best of both worlds by defining your own column list with ps -eo pid,ppid,user,stat,%cpu,%mem,rss,args.

Advertisement

Take care not to add a hyphen before aux: in POSIX/UNIX syntax, ps -aux means 'show processes for a user literally named x' (and prints a syntax warning on GNU/Linux). Always write ps aux without a dash or ps -ef with a dash.

When combining short flags on the command line, POSIX and GNU utilities allow clustering boolean flags behind a single hyphen, provided any option taking an argument appears last. In automated shell scripts, using long-form GNU options where portable makes self-documenting code that is easier to audit during peer review.

Practical Basic and Advanced Usage Examples

1. List All Running Processes with CPU and Memory Metrics (ps aux)

Use BSD-style ps aux to inspect all running user and daemon processes with CPU, memory, resident set size (RSS), and process state codes.

ps aux | head -n 6

# Illustrative output (reviewed against documentation)
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.0  0.3 168940 13420 ?        Ss   Sep10   0:42 /sbin/init
root         892  0.0  0.1  15420  7680 ?        Ss   Sep10   0:01 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
postgres     984  0.1  1.8 218400 74216 ?        Ss   Sep10   4:18 /usr/lib/postgresql/16/bin/postgres -D /var/lib/postgresql/16/main
root        1104  0.0  0.2  55840  8920 ?        Ss   Oct20   0:00 nginx: master process /usr/sbin/nginx -g daemon on;
www-data   29410  0.4  0.3  56412 12440 ?        S    19:12   0:08 nginx: worker process

VSZ shows total virtual address space in KiB, RSS shows actual non-swapped physical RAM in KiB, and STAT 'Ss' indicates an interruptible sleeping session leader.

2. Find the Top 10 Memory-Consuming or CPU-Consuming Processes

Combine ps -eo custom formatting with --sort=-%mem or --sort=-%cpu to rank the heaviest processes on a server.

ps -eo pid,ppid,user,%mem,%cpu,rss,comm --sort=-%mem | head -n 6

# Illustrative output (reviewed against documentation)
PID    PPID USER     %MEM %CPU    RSS COMMAND
   4120       1 mysql    28.4  6.2 1164280 mysqld
   2190       1 redis     8.1  1.4  331840 redis-server
    984       1 postgres  1.8  0.1   74216 postgres
  18420    1102 appuser   1.5 14.8   61440 python3
  29410    1104 www-data  0.3  0.4   12440 nginx

Prefixing the sort key with a minus sign (--sort=-%mem) orders processes from highest to lowest resident memory usage.

3. Visualize Parent-Child Process Trees with --forest (or ps auxf)

Render an ASCII tree diagram showing how systemd, SSH sessions, and worker pools spawned their child processes.

ps -ef --forest | grep -E 'PID|sshd|nginx' | grep -v grep

# Illustrative output (reviewed against documentation)
UID          PID    PPID  C STIME TTY          TIME CMD
root         892       1  0 Sep10 ?        00:00:01 /usr/sbin/sshd -D
root       14198     892  0 18:40 ?        00:00:00  \_ sshd: admin [priv]
admin      14220   14198  0 18:40 ?        00:00:00      \_ sshd: admin@pts/0
admin      14221   14220  0 18:40 pts/0    00:00:00          \_ -bash
root        1104       1  0 Oct20 ?        00:00:00 nginx: master process /usr/sbin/nginx
www-data   29410    1104  0 19:12 ?        00:00:08  \_ nginx: worker process
www-data   29411    1104  0 19:12 ?        00:00:07  \_ nginx: worker process

The --forest option (or BSD ps auxf) indents child processes beneath their parent PID so you can trace process lineage at a glance.

4. Filter Processes by Exact Command Name (-C) or User (-u)

Query specific services or user accounts directly inside ps without piping to grep.

ps -C nginx -o pid,ppid,user,stat,rss,args

# Illustrative output (reviewed against documentation)
PID    PPID USER     STAT   RSS COMMAND
   1104       1 root     Ss    8920 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
  29410    1104 www-data S    12440 nginx: worker process
  29411    1104 www-data S    12180 nginx: worker process

Using ps -C nginx selects only processes whose executable name in /proc/PID/stat is nginx, keeping the column header intact.

5. Inspect Individual Threads (LWP) Inside a Multi-Threaded Process (-L)

Pass -L with -p <PID> to view every Light-Weight Process (thread ID / LWP) and its per-thread CPU utilization.

ps -L -p 4120 -o pid,lwp,nlwp,psr,%cpu,stat,comm | head -n 6

# Illustrative output (reviewed against documentation)
PID     LWP NLWP PSR %CPU STAT COMMAND
   4120    4120   38   0  0.1 Sl   mysqld
   4120    4145   38   2  3.4 Rl   mysqld
   4120    4146   38   5  2.1 Sl   mysqld
   4120    4147   38   1  0.0 Sl   mysqld
   4120    4148   38   3  0.6 Sl   mysqld

LWP shows the kernel Thread ID, NLWP shows the total thread count (38), and PSR indicates which logical CPU core (0..N) the thread is currently scheduled on.

6. Map Processes to Their systemd Unit and Control Group Slice

Include the unit and cgroup format specifiers in ps -o to see which systemd service owns each process.

ps -eo pid,user,unit:28,comm --sort=unit | grep -E 'UNIT|.service' | head -n 6

# Illustrative output (reviewed against documentation)
PID USER     UNIT                         COMMAND
    741 root     cron.service                 cron
   1104 root     nginx.service                nginx
  29410 www-data nginx.service                nginx
    984 postgres [email protected]   postgres
    892 root     ssh.service                  sshd

Specifying unit:28 widens the UNIT column to 28 characters so long systemd service names are not truncated.

Real-World Workflows, Pipelines, and Shell Automation

Detect Zombie (Z) and Uninterruptible Disk-Wait (D) Processes

Run a diagnostic one-liner during server slowdowns to isolate any defunct zombie processes or tasks stuck in kernel I/O wait along with their parent PIDs and kernel wait channels.

#!/usr/bin/env bash
set -euo pipefail

echo "=== Checking for Zombie (Z) or Uninterruptible Sleep (D) processes ==="
ps -eo pid,ppid,user,stat,wchan:22,etimes,args | awk 'NR==1 || $4 ~ /^[ZD]/'

# Illustrative output (reviewed against documentation)
=== Checking for Zombie (Z) or Uninterruptible Sleep (D) processes ===
    PID    PPID USER     STAT WCHAN                  ELAPSED COMMAND
  27900   27850 backup   D    nfs_wait_bit_uninterr     1420 cp -r /mnt/nfs/archive /tmp/restore
  30112    1890 appuser  Z    -                          310 [sh] <defunct>

The WCHAN column reveals the exact kernel function where a D-state process is blocked (here nfs_wait_bit_uninterruptible, pointing immediately to a stalled NFS mount).

Calculate Total Physical RAM (RSS) Used by a Multi-Process Service

Sum the RSS column across all worker processes of a pre-forking service (like Apache, PHP-FPM, or PostgreSQL) to measure its true aggregate footprint.

ps -C php-fpm8.3 -o rss= | awk '
  { sum += $1; count++ }
  END {
    if (count > 0)
      printf "Processes: %d | Total RSS: %.2f MiB | Avg per worker: %.2f MiB
", count, sum/1024, (sum/count)/1024
    else
      print "No matching processes running."
  }'

# Illustrative output (reviewed against documentation)
Processes: 12 | Total RSS: 486.50 MiB | Avg per worker: 40.54 MiB

Appending '=' to the column specifier (-o rss=) suppresses the header row so awk can sum the raw kilobyte integers directly.

Pipelines, Redirection, Quoting, and Shell Expansion

When embedding ps inside shell pipelines (|), conditional chains (&& and ||), or command substitutions ($(...)), the calling shell performs tilde expansion, variable interpolation, and globbing before invoking the binary. Always wrap paths, patterns, and variables in quotes so whitespace and wildcard characters (*, ?) are not expanded prematurely, and use set -euo pipefail in unattended scripts.

Permissions, Security Implications, and Safe Execution

Never pass secrets, API tokens, or database passwords as command-line arguments (e.g., mysql -pSecretPassword or curl -u user:secret) on a multi-user Linux system. Because ps aux and ps -ef read /proc/PID/cmdline, which is world-readable by default, any local user or compromised container sharing the PID namespace can see command-line arguments in plain text.

Instead, pass sensitive credentials via environment variables, protected configuration files (chmod 0600), or standard input (--password-stdin), and consider mounting /proc with hidepid=2 on shared hosts.

GNU/Linux, BSD, and BusyBox Implementation Differences

ps is notorious for option differences across Unix derivatives. On Linux (procps-ng), both ps -ef and ps aux work, and --sort is supported. On macOS and FreeBSD, GNU --sort and -C do not exist; use ps aux -m (sort by memory) or ps aux -r (sort by CPU) on BSD/macOS.

On Alpine Linux, the default BusyBox ps ignores most flags and only supports -o (with limited fields) and -T; install apk add procps-ng if your scripts rely on full ps aux or ps -C functionality.

Troubleshooting Common Errors and Diagnostics

Warning: bad ps syntax, perhaps a bogus '-'?

Root Cause: You ran 'ps -aux' with a leading hyphen. In POSIX syntax, '-u x' attempts to filter processes owned by a user named 'x'.

Resolution: Omit the leading hyphen when using BSD options: run 'ps aux' instead of 'ps -aux'.

ps aux

Long command lines in ps output are cut off at 80 columns in scripts or cron jobs

Root Cause: When stdout is not an interactive terminal or when terminal width is narrow, older ps builds truncate output to 80 columns.

Resolution: Pass the ww modifier (ps auxww or ps -efww) to instruct ps to allow unlimited line width without truncation.

ps auxww | grep '[j]ava'

%CPU in ps aux does not match the live CPU percentage shown in top

Root Cause: ps calculates %CPU as total cumulative CPU time divided by total elapsed wall-clock time since the process started, whereas top measures instantaneous CPU usage over the last refresh interval (e.g., 3 seconds).

Resolution: Use top -b -n 2 -d 1 or pidstat 1 3 when you need instantaneous real-time CPU percentage over a short sampling window.

top -b -n 2 -d 1 | tail -n 15

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

4 FAQs
ps aux uses BSD syntax (no dash) and includes %CPU, %MEM, VSZ, RSS, and STAT columns. ps -ef uses UNIX System V syntax (with dash) and includes the Parent Process ID (PPID) column. Both list all running processes on the system.
R means running/runnable, S means interruptible sleep (waiting for an event), D means uninterruptible sleep (usually disk or NFS I/O), T means stopped/traced, and Z means zombie (defunct). Modifiers include s (session leader), l (multi-threaded), < (high priority), N (low priority), and + (foreground group).
Add --sort=-%mem to sort by highest memory usage first, or --sort=-%cpu to sort by highest CPU usage first (for example: ps aux --sort=-%mem | head -n 15).
Either use pgrep -fa <name> instead, or bracket the first character of the search pattern in grep—such as ps aux | grep '[n]ginx'—so the literal regex '[n]ginx' does not match the string 'nginx' in the target process's command line.
RR
Written byVerified Author

Rajesh Ray

I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout