65. Process Management - ps
Contents
We can view snapshot information for the current processes through the ps command.
Current Processes Snapshot
Command Options
Here are some common basic options for ps command:
| Option | Description |
|---|---|
| -A, -e | Output all processes. |
| -a | Output all tty(TeleTYpewriter or terminal). |
| a | Output all tty include other users. |
| -d | Output all processes except the session leaders. |
| r | Output all running processes. |
| T | Output all processes on this terminal. |
List Options
Here are some common list options for ps command:
These options accept multiple arguments, for example: ps -C “cmd1 cmd2” or ps -C cmd1, cmd2.
| Option | Description |
|---|---|
| -C cmdlist | Output the process through the command name. |
| -G grplist or ‑‑Group grplist | Output the process by a real group ID or name. |
| -g grplist or ‑‑group grplist | Output the process by a valid group ID or name. |
| p pidlist or -p pidlist or ‑‑pid pidlist | Output the process by the process’s ID. |
| ‑‑ppid pidlist | Output the process by the process’s parent ID. |
| q pidlist or -q pidlist or ‑‑quick-pid pidlist | Output the process by the process’s ID in quick mode. |
| -s sesslist or ‑‑sid sesslist | Output the process by the process’s session ID. |
| t ttylist or -t ttylist or ‑‑tty ttylist | Output the process by the a terminal. |
| U userlist or -u userlist or ‑‑user userlist | Output the process by a valid user ID or name. |
| -U userlist or ‑‑User userlist | Output the process by a real user ID or name. |
Output Format
Here are some common output format options for ps command:
| Option | Description |
|---|---|
| -c | Output different scheduling information for the-l option. |
| ‑‑context | Output security context format for SELinux. |
| -f | Output full format list. |
| -F | Output an extra full format list. |
| ‑‑format format or -o format or o format | Output user-specified format. |
| j | Output BSD job control format. |
| -j | Output jobs format. |
| l | Output BSD long format. |
| -l | Output long format, usually used with -y option. |
| -M or Z | Add a column of security data to the output for SELinux. |
| O format | Preloaded o. |
| -O format | Identical to -o pid,format,state,tname,time,command or -o pid,format,tname,time,cmd. |
| s | Output signal format. |
| u | Output user-oriented format. |
| v | Output virtual memory format. |
| X | Output register format. |
| -y | Output without flags, show rss in place of addr, can only be used with -l. |
Output Modifiers
Here are some common output modifiers for ps command:
| Option | Description |
|---|---|
| c | Output the true command name. |
| e | Output the environment after the command. |
| f | Output the process hierarchy in ASCII tree format. |
| –forest or -H | Output the current terminal’s process hierarchy in ASCII tree format. |
| h or ‑‑no-header or ‑‑no-headers | Output without header. |
| ‑‑header or ‑‑headers | Output with header, one per page. |
| S | Output some up information. |
| w or -w | Widen the output length. |
Output Threads
Here are some common thread display options for ps command:
| Option | Description |
|---|---|
| H | Output threads as processes. |
| -L | Output threads through the LWP and NLWP columns. |
| m or -m | Output threads after processes. |
| -T | Output threads through the SPID column. |
Standard Format Specifiers
Here are some common standard format specifiers of command options:
| Format Specifier | Description |
|---|---|
| %CPU | The percentage of CPU usage that the process occupies. |
| %MEM | The percentage of physical memory size that the process uses. |
| COMMAND | The command used to run the process. |
| START | The time when the process began to run. |
| TIME | The time the process has been running. |
| STAT | The status code of the process. |
| PID | The number represented as the process id. |
| RSS | Non swapped physical memory consumed by the process. (Kilobyte) |
Process State Codes
Here are some process state codes of STAT or S specifiers:
| Process Code | Description |
|---|---|
| D | The I/O processes in uninterruptible sleep. |
| I | Threads that are idle in the kernel. |
| R | Running or runnable processes in a run queue. |
| S | The I/O processes in interruptible sleep. |
| T | Processes that are stopped through job control signal. |
| t | Processes that are stopped through debugger during tracing. |
| X | Dead processes that should no longer be seen. |
| Z | Dead processes that weren’t captured by the parent process. |
Here are some BSD format process state codes of STAT specifiers:
| Process Code | Description |
|---|---|
| < | Processes with high priority. |
| N | Processes with low priority. |
| L | Real-time and custom IO processes that have pages locked into memory. |
| s | Processes that are session leader processes. |
| l | Multi-threaded processes. |
| + | Processes in the foreground process group. |
AIX Format Descriptors
Here are some common descriptors for ps command:
They are used with the output format options, for example ps o %C or ps -o %C or ps ‑‑format %C.
| Descriptor | Header |
|---|---|
| %C | %CPU |
| %G | GROUP |
| %P | PPID |
| %U | USER |
| %a | COMMAND |
| %c | COMMAND |
| %g | RGROUP |
| %n | NI |
| %p | PID |
| %r | PGID |
| %t | ELAPSED |
| %u | RUSER |
| %x | TIME |
| %y | TTY |
| %z | VSZ |
Other Information
Here are some other options for ps command:
| Option | Description |
|---|---|
| ‑‑help s | Output all basic options. |
| ‑‑help l | Output all list options. |
| ‑‑help o | Output all output modifiers. |
| ‑‑help t | Output all threads options. |
| ‑‑help m | Output all miscellaneous options. |
| L | Output all format specifiers. |
Common Parameter Combinations
Use Standard Syntax to View All Processes
|
|
Use the BSD Syntax to View All Processes
|
|
View All Processes in a Tree Format
|
|
View Threads for All Processes
|
|
View Security Information for All Processes
|
|
References PS(1)
Author Dong Chen
LastMod Sat Apr 6 2019