Which language do you prefer? English 简体中文 繁体中文
...

Part of Linux Commands Cheat Sheet

"ps" stands for "processes".

Show processes information.

Show processes in current shell


ps

Sample output:


  PID TTY          TIME CMD
 6472 pts/1    00:00:00 bash
 6686 pts/1    00:00:00 ps

Fields:

  • PID: process ID
  • TTY: terminal associated with the process
  • TIME: total CPU usage
  • CMD: command

About the output fields, check man page.

What does '?' represent under TTY: What does '?' represent under TTY - Unix & Linux Stack Exchange

Show every process on the system


ps -e

# -f for full-format listing
ps -ef

# -F for full-format listing (with extra information)
ps -eF

# -H for tree view (or --forest)
ps -eFH

# BSD style
#   a for all users
#   u for user-oriented format
#   x for processes without a controlling terminal
ps aux

# f for tree view (or --forest)
ps auxf

Sample output:


USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
ubuntu    2129  0.0  0.3  30760 12348 pts/1    Ss   01:16   0:00 -bash
ubuntu   10270  0.0  0.3  30628 12392 pts/0    Ss+  01:20   0:00 -bash
ubuntu   15809  0.0  0.0  38428  3404 pts/1    R+   01:37   0:00 ps u

About the output fields, check man page.

If you have a narrow terminal window, you may notice that lines are cut to fit in terminal window, like:

www-data 26579  0.0  0.2 146492  9984 ?        S    Jun19   0:00 nginx: worker pr

You can pass w (or -w) for wide output, which display single process in multiple lines (but still with a limited width), and pass w twice (ww, or -ww) will give you an unlimited-width output.

www-data 26579  0.0  0.2 146492  9984 ?        S    Jun19   0:00 nginx: worker pr
ocess

Specify columns


ps -eo pid,%cpu,%mem,command

Sort processes


ps aux --sort=%mem
ps aux --sort=-%cpu

ps -eo pid,%cpu,%mem,command --sort=%mem
ps -eo pid,%cpu,%mem,command --sort=-%cpu

# find top 5 memory usage processes
# --no-headers for no headers line
ps --no-headers -eo pid,%cpu,%mem,command --sort=-%mem | head -n 5

About sortable fields, check man page.

Search processes

Use pgrep instead: Pgrep Command in Linux

Use pgrep with ps:


# list processes with command node
pgrep node | xargs --no-run-if-empty ps -p

Search and kill processes

Use pkill instead: Pkill Command in Linux

References

ps(1) — Linux manual page

Ps Command in Linux (List Processes) | Linuxize

Linux and Unix ps command tutorial with examples | George Ornbo

wbswjc-blog