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.
ps aux ps -ef ps -o pid,ppid,stat,comm -p PID
Try it
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.
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
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 xfinds itself. Thegrepprocess matches its own pattern. Usepgrep(pgrepandpkill),ps -C name, or the trickgrep '[x]yz'.commis cut to 15 characters, andps -Cuses that name. Useargsorpgrep -ffor long names.- A snapshot, not a stream. CPU% from
psis the average over the process lifetime, not now. For current load usetop. - Zombies (
Z,<defunct>) are finished children whose parent has not collected them yet; kill the parent or fix itswaithandling, you cannot kill a zombie itself. - For scripts, name your columns with
-oand=instead of cuttingps auxby position. Output ofargsmay contain spaces; put it last. - Memory:
rsscounts shared pages in every process that maps them, so summing it overstates real use. - Containers show only their own processes unless the host's
/procis shared. - Tree view:
pstreeorps -ejH.
Related
top,pgrepandpkill,kill,pstree,lsof- Lessons: Processes, Jobs and background tasks