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 |
|---|---|---|
| Effective user | |
| Process ID | |
| CPU time used divided by time the process has been running | percent of one CPU |
|
| percent |
| Virtual memory size | KiB |
| Resident set size, non-swapped physical memory | KiB |
| Controlling terminal; | |
| State plus modifier flags | |
| Start time (date if more than a day ago) | |
| Cumulative CPU time | minutes:seconds |
| Command line; |
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:
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. SummingRSSoverstates total use, sometimes dramatically.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 |
|---|---|---|
| Running or runnable (on a run queue) | Using or waiting for CPU |
| Interruptible sleep | Waiting for an event; normal for most daemons |
| Uninterruptible sleep, usually I/O | Cannot be interrupted, even by |
| Idle kernel thread | Ignore |
| Stopped by a job control signal | Someone pressed Ctrl+Z or sent |
| Stopped by a debugger during tracing |
|
| Zombie: exited, not yet reaped by its parent | Holds only a process table slot |
| Dead | Should never be seen |
Modifier characters that follow on BSD-format output:
Modifier | Meaning |
|---|---|
| High priority (negative nice) |
| Low priority (positive nice) |
| Has pages locked into memory |
| Session leader |
| 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 |
|---|---|
| Elapsed time since start, in seconds / human format |
| Exact start timestamp |
| Number of threads |
| Kernel function the task is sleeping in |
| CPU the task last ran on |
| Nice and priority |
| Control group, maps PIDs to containers and units |
| Full command line (same as |
| 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 -awith the same arguments beforepkill. Read the list.Prefer
-xfor name matches.pkill nodealso hitsnode_exporter.Be careful with
-f. Full command-line matching also matches shells,sshsessions,sudowrappers 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
-uor-Pwhen several tenants run the same binary.Send a polite signal first.
pkill -TERMlets the process clean up; use-KILLonly 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 | It is a lifetime average | Use |
Summing | Shared pages double counted | Sum |
Panicking over large | Reserved address space, not RAM | Watch |
| It is already dead | Fix or restart the parent |
| Matches shells and scripts |
|
Key takeaways
ps%CPUis CPU time over lifetime; sample tools show what is busy now.VSZis address space,RSSis resident pages with shared pages counted repeatedly,PSSis the fair share.The first
STATletter is the state;Dcrowds mean storage trouble,Zcrowds mean a parent not reaping.ps -eo ... --sort=with keys likeetimes,wchan,cgroupandnlwpturnspsinto a precise incident tool.Preview with
pgrep -a, match exactly with-x, and anchor-fpatterns before youpkill.
References
ps(1)manual (procps-ng): https://man7.org/linux/man-pages/man1/ps.1.htmlpgrep(1)/pkill(1)manual: https://man7.org/linux/man-pages/man1/pgrep.1.html/proc/<pid>/smaps_rollupand memory fields: https://docs.kernel.org/filesystems/proc.htmlwait(2)and zombie processes: https://man7.org/linux/man-pages/man2/wait.2.htmlprocps-ng project: https://gitlab.com/procps-ng/procps
Comments
0No comments yet. Be the first to comment!
Sign In to post a comment.