ps aux is usually the first command typed on a misbehaving Linux box and the one most often misread. People sort by %CPU and chase a process that was busy an hour ago, add up RSS and conclude the server uses twice its RAM, or pkill -f a pattern that also matches the deploy script running the command.

This guide explains each column of the BSD-style ps aux output from procps-ng (4.0.4 on Ubuntu 24.04, similar on RHEL 9), decodes the STAT letters, and then shows how to build your own views with ps -eo and how to use pgrep and pkill without collateral damage.

Reading ps aux

ps aux | head -5
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.0  0.1  22540 13400 ?        Ss   Dec20   0:09 /sbin/init
root         812  0.0  0.0      0     0 ?        I<   Dec20   0:00 [kworker/u17:0-ttm]
www-data    2231  4.1  6.8 1873920 549312 ?      Sl   09:12   3:47 /usr/bin/node /srv/app/server.js
postgres    2744  0.3  2.1 4421616 172288 ?      Ss   Dec20   6:02 postgres: checkpointer

The letters a, u and x mean: all users' processes, user-oriented columns, and include processes without a terminal. Without x you would miss every daemon.

Column

Meaning

Unit

USER

Effective user

PID

Process ID

%CPU

CPU time used divided by time the process has been running

percent of one CPU

%MEM

RSS as a share of physical memory

percent

VSZ

Virtual memory size

KiB

RSS

Resident set size, non-swapped physical memory

KiB

TTY

Controlling terminal; ? means none

STAT

State plus modifier flags

START

Start time (date if more than a day ago)

TIME

Cumulative CPU time

minutes:seconds

COMMAND

Command line; [name] in brackets is a kernel thread

The %CPU trap

The ps man page is explicit: %CPU is CPU time divided by elapsed run time. It is a lifetime average, not a current reading. A worker that spun at 100% for ten minutes after start and has idled for two days still shows a few percent; a process that just went into a tight loop after a week of idling shows almost nothing.

For "what is busy right now", use top, htop, or pidstat 1 from the sysstat package, which sample over an interval. Use ps %CPU only to spot processes that have been expensive across their whole life.

VSZ versus RSS

VSZ is the size of the virtual address space: code, libraries, heap, stacks, memory-mapped files and regions reserved but never touched. Runtimes such as the JVM, Go and Node reserve large ranges up front, so a VSZ of tens of gigabytes on a small VM is normal and harmless.

RSS is the number of pages of that address space currently in physical RAM. It is the closer measure of real memory use, with two caveats:

  1. Shared pages are counted in every process that maps them. Ten PHP-FPM workers sharing the same opcache and libraries each report the shared part in their own RSS. Summing RSS overstates total use, sometimes dramatically.

  2. Swapped-out pages are not included. A process under memory pressure can look smaller than it is.

When you need a fair per-process number, read proportional set size (PSS), which divides each shared page among the processes sharing it:

sudo grep -E '^(Rss|Pss|Swap):' /proc/2231/smaps_rollup
Rss:              549312 kB
Pss:              531904 kB
Swap:                  0 kB

Summing Pss across processes gives a total that actually matches the machine.

STAT codes

The first character is the process state. The procps man page lists these:

Code

State

What to think

R

Running or runnable (on a run queue)

Using or waiting for CPU

S

Interruptible sleep

Waiting for an event; normal for most daemons

D

Uninterruptible sleep, usually I/O

Cannot be interrupted, even by SIGKILL, until the I/O returns

I

Idle kernel thread

Ignore

T

Stopped by a job control signal

Someone pressed Ctrl+Z or sent SIGSTOP

t

Stopped by a debugger during tracing

gdb or strace attached

Z

Zombie: exited, not yet reaped by its parent

Holds only a process table slot

X

Dead

Should never be seen

Modifier characters that follow on BSD-format output:

Modifier

Meaning

<

High priority (negative nice)

N

Low priority (positive nice)

L

Has pages locked into memory

s

Session leader

l

Multi-threaded

+

In the foreground process group of its terminal

So Ssl is a sleeping, multi-threaded session leader (a typical systemd service), R+ is something running in the foreground of your shell, and D< is a high-priority task stuck waiting on I/O.

Two states deserve action when they pile up. Many D processes on the same mount point to slow or hung storage; check iostat -x 1 for local disks or dmesg for network filesystem timeouts. Many Z processes mean a parent is not calling wait(). You cannot kill a zombie, because it is already dead; fix or restart the parent, and init adopts and reaps the orphans.

# Parent of every zombie, with counts
ps -eo ppid=,stat= | awk '$2 ~ /^Z/ {print $1}' | sort | uniq -c | sort -rn

Custom output with ps -eo

aux is a fixed layout. The -o option lets you choose columns, which is what you want for scripts and incident notes. -e selects every process.

# Top memory users with useful context
ps -eo pid,ppid,user,stat,rss,vsz,etimes,nlwp,comm --sort=-rss | head -15

Handy format keys:

Key

Shows

etimes / etime

Elapsed time since start, in seconds / human format

lstart

Exact start timestamp

nlwp

Number of threads

wchan:32

Kernel function the task is sleeping in

psr

CPU the task last ran on

ni, pri

Nice and priority

cgroup

Control group, maps PIDs to containers and units

args

Full command line (same as cmd)

comm

Executable name only

Append = to a key to suppress its header, which keeps script parsing simple: ps -o rss= -p 2231 prints only the number.

Examples that come up during incidents:

# Tasks stuck in D state and where in the kernel they wait
ps -eo pid,stat,wchan:32,args | awk 'NR==1 || $2 ~ /^D/'

# Threads of one process with their own CPU usage
ps -L -o tid,stat,pcpu,comm -p 2231

# Processes started in the last 10 minutes (new spawns during an incident)
ps -eo pid,etimes,user,args --sort=etimes | awk 'NR==1 || $2 < 600'

# Which systemd unit or container owns each heavy process
ps -eo pid,rss,cgroup:60,comm --sort=-rss | head

ps -ef (System V style) is also common; it shows UID PID PPID C STIME TTY TIME CMD and is handy for seeing parents. ps -ejH or ps axjf prints a process tree when pstree is not installed.

pgrep and pkill without surprises

pgrep returns PIDs whose name matches a pattern, and pkill sends a signal to them. By default the pattern is an extended regular expression matched against the process name (up to 15 characters), not the full command line.

pgrep -a nginx                 # PIDs plus full command line
pgrep -u postgres -l           # by user, with names
pgrep -x node                  # exact name match, not "nodemon" or "node_exporter"
pgrep -f 'server.js --port 3000'   # match the full command line
pgrep -o nginx                 # oldest match (usually the master)
pgrep -c php-fpm               # count only

Rules that prevent accidents:

  • Always run pgrep -a with the same arguments before pkill. Read the list.

  • Prefer -x for name matches. pkill node also hits node_exporter.

  • Be careful with -f. Full command-line matching also matches shells, ssh sessions, sudo wrappers and CI scripts whose arguments contain the pattern. Anchor it: pgrep -f '^/usr/bin/node /srv/app/server.js'.

  • Scope by user or parent with -u or -P when several tenants run the same binary.

  • Send a polite signal first. pkill -TERM lets the process clean up; use -KILL only after it has had time to exit.

For services managed by systemd, prefer systemctl kill --signal=TERM app.service or systemctl restart, which target exactly the unit's cgroup and nothing else.

Common mistakes

Mistake

Why it hurts

Do this instead

Sorting ps aux by %CPU for current load

It is a lifetime average

Use top, htop or pidstat 1

Summing RSS to get total memory

Shared pages double counted

Sum Pss from smaps_rollup

Panicking over large VSZ

Reserved address space, not RAM

Watch RSS/Pss trends

kill -9 on a zombie

It is already dead

Fix or restart the parent

pkill -f pattern unanchored

Matches shells and scripts

pgrep -a first, anchor the regex

Key takeaways

  • ps %CPU is CPU time over lifetime; sample tools show what is busy now.

  • VSZ is address space, RSS is resident pages with shared pages counted repeatedly, PSS is the fair share.

  • The first STAT letter is the state; D crowds mean storage trouble, Z crowds mean a parent not reaping.

  • ps -eo ... --sort= with keys like etimes, wchan, cgroup and nlwp turns ps into a precise incident tool.

  • Preview with pgrep -a, match exactly with -x, and anchor -f patterns before you pkill.

References