Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Processes and Signals

Linux ps command

Reference for the Linux ps command: list processes with aux or -ef, choose columns with -o, sort, select by user or PID, and read the STAT state codes.

ps prints a snapshot of the processes running at the moment you call it. It reads the /proc filesystem and prints one line per process: ID, owner, state, memory, command. It is the tool behind most scripts that need to know whether something is running, and the first thing to reach for when a machine feels slow.

ps has a confusing history: it accepts three option styles at once. Unix options have a dash (ps -ef), BSD options have none (ps aux), and GNU long options use two dashes (ps --sort=-%mem). The two famous spellings ps aux and ps -ef give nearly the same list in different columns. Mixing styles can change the meaning, so pick one.

Terminal
ps aux
ps -ef
ps -o pid,ppid,stat,comm -p PID

Try it

Bash Choosing columns with -o

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Find, count and sort

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
ps [OPTIONS]
Option Description
-e, -A All processes.
-f, -F Full-format / extra-full listing (UID, PPID, start time).
aux BSD style: all processes with owner and CPU/memory columns, including those without a terminal.
-u USER, -U USER Processes of an effective / real user.
-p PIDS Select by PID (comma-separated).
-C NAME Select by exact command name.
--ppid PID Children of PID.
-o LIST Choose output columns, for example pid,ppid,%cpu,%mem,etime,args. Add = after a name to suppress its header (pid=).
--sort=KEY Sort; prefix with - for descending (--sort=-%mem).
-H, f, --forest Show the process tree.
-T, -L Show threads.
--no-headers Omit the header line.

Useful columns: pid, ppid, uid, user, comm (name), args (full command line), stat, etime (elapsed), %cpu, %mem, rss (resident KiB), vsz, nlwp (threads).

State codes (STAT): R running, S sleeping, D uninterruptible wait (usually disk), T stopped, Z zombie. Suffixes: s session leader, + foreground, l multithreaded, < high priority, N low priority.

Returns: 0 if at least one process matched, 1 if none matched (useful in scripts), 2 for bad syntax.

Usage notes

  • ps aux | grep x finds itself. The grep process matches its own pattern. Use pgrep (pgrep and pkill), ps -C name, or the trick grep '[x]yz'.
  • comm is cut to 15 characters, and ps -C uses that name. Use args or pgrep -f for long names.
  • A snapshot, not a stream. CPU% from ps is the average over the process lifetime, not now. For current load use top.
  • Zombies (Z, <defunct>) are finished children whose parent has not collected them yet; kill the parent or fix its wait handling, you cannot kill a zombie itself.
  • For scripts, name your columns with -o and = instead of cutting ps aux by position. Output of args may contain spaces; put it last.
  • Memory: rss counts shared pages in every process that maps them, so summing it overstates real use.
  • Containers show only their own processes unless the host's /proc is shared.
  • Tree view: pstree or ps -ejH.