linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
  • Introduction
  • Lessons
  • How it works
  • Simulator
  • Knowledge base
  • Interview prep
Index
Categories
All entries
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.
home/linux/kb/Commands/cmd-ps

kb/commands ── Commands ── beginner

ps: process snapshot

ps prints a snapshot of processes at the moment it runs. Two dialects: BSD (`aux`, no dash) and UNIX (`-ef`, with dash). `-o` specifies columns. For continuous monitoring, use [[cmd-htop|htop]].

view as markdownaka: ps, ps-aux, ps-ef, ps-command

Why ps

When you need a one-shot process list for a script, a pipe, or logs, ps is the right tool. For interactive use, see [[cmd-htop|htop]]. For a single process, use top -p PID or cat /proc/PID/status.

ps reads /proc/*/stat, cmdline, and status, the same sources htop uses, but captures a single frame.

Two dialects and why it hurts

Historically:

  • BSD style: ps aux (NO dash), short single-letter options
  • UNIX style: ps -ef (WITH dash), System V

Modern procps-ng (Linux) accepts both, plus ps --GNU (double dash). Mixing options from different styles in one call is a source of bugs:

ps -aux        ← UNIX -a + parsed as BSD `aux`. Often works, but not
                guaranteed (different ps builds interpret this differently).

The rule: use either ps aux or ps -ef.

ps aux: what it shows

bash
$ ps aux | head -3
USER  PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root    1  0.0  0.1 168740 11252 ?        Ss   Apr01   0:23 /sbin/init
root    2  0.0  0.0      0     0 ?        S    Apr01   0:00 [kthreadd]

Columns:

ColumnMeaning
USERowner
PIDprocess id
%CPUaverage since start (not realtime!)
%MEMRSS / total RAM
VSZvirtual size in KiB (includes mmap regions and non-resident pages)
RSSresident set size in KiB, what is actually in RAM
TTYcontrolling terminal; ? means none (daemon)
STATstate; see below
STARTwhen started
TIMEtotal CPU time
COMMANDargv

STAT flags

  • R: running or runnable
  • S: interruptible sleep (normal for most processes)
  • D: uninterruptible sleep (usually I/O; cannot be killed even with SIGKILL)
  • T: stopped (Ctrl-Z, SIGSTOP)
  • Z: zombie (exited, but parent has not reaped it)
  • I: kernel idle thread (procps-ng 3.3+)

Additional flags:

  • s: session leader
  • l: multi-threaded
  • +: foreground in its process group
  • <: high priority (nice < 0)
  • N: low priority (nice > 0)
  • L: has locked pages

Example: Ssl+ means session leader, sleeping, multi-threaded, foreground.

ps -ef: a slightly different set

bash
$ ps -ef | head -3
UID    PID  PPID  C STIME TTY      TIME     CMD
root     1     0  0 Apr01 ?        00:00:23 /sbin/init
root     2     0  0 Apr01 ?        00:00:00 [kthreadd]
  • PPID: parent PID (absent in ps aux without f)
  • C: CPU utilization
  • STIME: start time
  • CMD: equivalent of COMMAND

When you need PPID, ps -ef is shorter than ps -eo pid,ppid,....

-o: custom format

The most flexible mode. List columns separated by commas:

bash
ps -eo pid,ppid,user,nice,pri,rss,vsz,stat,wchan,cmd

Commonly used fields:

FieldMeaning
pid, ppid, pgid, sidids
user, uid, group, gidowners
nice (ni), pripriority
rss, vsz, pmemmemory
pcpu, time, etimeCPU and time
stat, statestate
wchankernel location where the process is sleeping
comm, cmd, argsname/argv
cgroupcgroup path (systemd unit name, container)
lstartabsolute start timestamp
tty, class, policymiscellaneous

Rename a column header with =: ps -eo pid,user,rss=Memory_KB,cmd.

Sorting: --sort=-%cpu (minus means descending):

bash
ps -eo pid,user,pcpu,pmem,cmd --sort=-pcpu | head

Thread view

By default ps shows only processes. To see threads:

bash
ps -eLf            # all threads (-L) with extended form (-f)
ps -T -p $PID      # threads of a specific process
ps -o pid,tid,nlwp,cmd $PID
  • PID: process id (TGID in the kernel)
  • LWP / TID: thread id (PID in the kernel)
  • NLWP: number of threads in the process

Tree mode

bash
ps -ef --forest       # ASCII tree
ps auxf
pstree -p             # separate utility, cleaner output
pstree -psaT 1        # tree with PIDs and cmdline

Common use cases

bash
# Top 10 by CPU
ps -eo pid,user,pcpu,cmd --sort=-pcpu | head -11
# Top 10 by memory
ps -eo pid,user,rss,cmd --sort=-rss | head -11
# All processes of a user
ps -fu www-data
# How long a process has been running
ps -o pid,etime,cmd -p $PID
# All zombies
ps -eo pid,ppid,stat,cmd | awk '$3 ~ /^Z/'
# PIDs of nginx (for xargs)
pgrep nginx        # alternative to ps + grep
pidof nginx

For scripting, pgrep/pidof is cheaper and clearer than ps | grep.

When something looks wrong

  • ps aux | grep foo shows grep itself. Use pgrep foo or pgrep -f (matches against cmdline). Or use ps aux | grep '[f]oo'.
  • %CPU over 100. That is the sum across all CPUs for a multi-threaded process. Use ps -eL for per-thread values.
  • VSZ is enormous (TB), RSS is small. Normal: VSZ includes mmap regions that are not resident. Look at RSS instead.
  • No argv visible ([kworker/...]). Kernel thread, no userspace argv. Brackets mean kernel thread.
  • Script truncates COMMAND. The terminal is narrow. ps -e -ww -o cmd disables truncation.
  • ps in a pipe sees its own PID. Standard behavior. Ignore it or filter it out.

Alternatives

  • pgrep/pkill: search or kill by name or cmdline pattern
  • pidof: PID by exact binary name
  • /proc/$PID/status: read data for one process directly
  • top/[[cmd-htop|htop]] - interactive

§ команды

bash
ps aux | grep '[s]shd'

All sshd processes, without grep matching itself. The bracket trick prevents the grep pattern from appearing in its own output.

bash
ps -eo pid,user,pcpu,pmem,cmd --sort=-pcpu | head

Top processes by CPU. A typical one-liner for a quick check.

bash
ps -eo pid,etime,cmd -p $(pgrep -d, nginx)

How long each nginx process has been running, using elapsed time.

bash
ps -ef --forest

All processes as a tree, showing which process spawned which.

bash
ps -o pid,tid,cmd -L -p 1234

All threads of process 1234, with LWP/TID.

bash
ps -eo pid,cgroup,cmd | grep docker

Processes inside Docker containers, identified by cgroup path.

bash
ps -eo pid,stat,cmd | awk '$2 ~ /Z/'

Only zombie processes, to find uncollected children.

§ см. также

  • cmd-htophtop: interactive process monitorhtop is an interactive TUI process monitor. F-keys: F3 search, F4 filter, F5 tree, F6 sort, F9 kill. Color meters at the top, process list below. It replaces top wherever it is available.
  • cmd-lsoflsof: who has what open`lsof` (List Open Files) shows every open file across all processes. In Linux everything is a file, so that includes regular files, sockets, and pipes.
  • cmd-stracestrace: what syscalls a process makes`strace` shows in real time which system calls a process makes and with what arguments. The primary tool when a process goes silent.
  • signalsSignals (SIGTERM, SIGKILL, SIGHUP)A signal is an asynchronous notification to a process from the kernel or another process. TERM asks it to quit, KILL kills it now, HUP reloads config.
  • process-and-pidProcess and PIDA process is a running program with its own PID, memory, open descriptors, and UID. Every process forms a tree rooted at init (PID 1).
Footer
linuxlab-
Copyright © 2026 LinuxLab. All rights reserved.
Tutorials
Pricing
About
Privacy & cookies