ps
shows a snapshot of a set of processes. ps
process itself, and
ps
is that some command line options come -f
specifies full-format listing while f
prints the processes in an ASCII art process tree. ps
lists the four columns PID | process id |
TTY | terminal associated with the process |
TIME | cumulative CPU time |
CMD | command that started the process |
$ ps PID TTY TIME CMD 5105 pts/3 00:00:00 bash 5373 pts/3 00:00:00 ps
$ ps -o pid,tty,time,cmd PID TT TIME CMD 5105 pts/3 00:00:00 -bash 5374 pts/3 00:00:00 ps -o pid,tty,time,cmd
stat=STAT
) and shows command argugments (args=COMMAND
) instead of the executable name: $ ps t pts/3 PID TTY STAT TIME COMMAND 5105 pts/3 Ss 0:00 -bash 5397 pts/3 R+ 0:00 ps t pts/3
a | Lift the BSD-style «only yourself» restriction, which is imposed upon the set of all processes when some BSD-style (without "-") options are used or when the ps personality setting is BSD-like. The set of processes selected in this manner is in addition to the set of processes selected by other means. An alternate description is that this option causes ps to list all processes with a terminal (tty), or to list all processes when used together with the x option. |
-A , -e | All processes. |
-a | All processes except both session leaders and processes not associated with a terminal. |
-d | All processes except session leaders. |
--deselect , -N | Reverse selection |
g | Obsolete, only useful in sunos4: really all processes, even session leaders. |
T | All processes associated with this terminal (TTY). Identical to the t option without any argument. |
r | Restrict the selection to only running processes. |
x | Lift the BSD-style "must have a tty" restriction, which is imposed upon the set of all processes when some BSD-style (without "-") options are used or when the ps personality setting is BSD-like. The set of processes selected in this manner is in addition to the set of processes selected by other means. An alternate description is that this option causes ps to list all processes owned by you (same EUID as ps), or to list all processes when used together with the a option. |
-C cmdlist | Select by command name. Compare with pidof and pgrep |
-G grplist , --Group grplist | Select by real group ID (RGID) or group name, i.e. the group of the user who created the process. |
--group grplist | Select by effective group ID (EGID) or name, i.e. the group whose file access permissions are used by the process. See also the -g option. |
-g sesorgrplist | Select by session (if all elements sesorgrplist are numeric) or by effective group name (if at least one element is textual). Compare with -s and --group options. |
p pidlist , -p pidlist , --pid pidlist | Select by process ID (PID). p does print the STAT column and process arguments, -p and --pid do not print these. ps p $procid is equal(?) to ps -$procid . |
--ppid pidlist | Select child processes of given (parent) process IDs. |
q pidlist , -q pidlist , --quick-pid pidlist | Quick mode: Select by process ID |
-s sesslist , --sid sesslist | Select by session ID. |
t ttylist | Select by tty. Nearly identical to -t and --tty , but can also be used with an empty ttylist to indicate the terminal associated with ps. Same as T option. |
-t ttylist , --tty ttylist | Select by tty which can be specified by /dev/ttyS1 , ttyS1 or simply S1 . A hyphen (-t - or --tty - ) indicates to select processes not attached to any terminal. |
U userlist , -u userlist , --user userlist | Select by effective user ID (EUID) or user name. |
-U userlist , --User userlist | Select by real user ID (RUID) or user name, i. e. the user who created the process. |
-c | Show different scheduler information for the -l option. |
--context | Display security context format (SELinux). |
-f | Do full-format listing. This option can be combined with many other UNIX-style options to add additional columns. It also causes the command arguments to be printed. When used with -L , the NLWP (number of threads) and LWP (thread ID) columns will be added. See the c option, the format keywords args and/or comm . |
-F | Extra full format. See the -f option, which -F implies. |
--format fmt , -o fmt , o fmt | User-defined format (allows to select columns). Add = to column name to suppress header. See format specifiers (whose list can be displayed with ps L ). |
j | BSD job control format. |
-j | Jobs format. |
l | Display BSD long format. |
-l | Long format. See also -y . |
-M , Z | Add a column of security data. (for SELinux). |
O fmt | is preloaded o (overloaded). The BSD O option can act like -O (user-defined output format with some common fields predefined) or can be used to specify sort order. Heuristics are used to determine the behavior of this option. To ensure that the desired behavior is obtained (sorting or formatting), specify the option in some other way (e.g. with -O or --sort ). When used as a formatting option, it is identical to -O , with the BSD personality. |
-O fmt | Like -o , but preloaded with some default columns. Identical to -o pid,format,state,tname,time,command or -o pid,format,tname,time,cmd |
-P | Add PSR column (i. e. the processor id) |
s | Display signal format. I believe this to be equivalent to ps -o uid,pid,pending,blocked,ignored,caught,stat,tty8,bsdtime,args |
u | Display user-oriented format. I believe this to be equivalent to ps -o user,pid,%cpu,%mem,vsz,rss,tty8,stat,start_time,bsdtime,args |
v | Display virtual memory format. I believe this to be almost equivalent to ps -o pid,tty8,stat,bsdtime,maj_flt,trs,drs,rss,%mem,args |
X | Register format. I believe this to be equivalent to ps -o pid,stackp,esp,eip,tmout,alarm,stat,tty8,bsdtime,args |
-y | Do not show flags; show rss in place of addr, can only be used with -l . |
fmt
(options --format
, -o
and o
) is given a list of comma or blank-separted format specifiers to specify the columns to be shown. PS_FORMAT
environment specifies a default format. ps -o pid,wchan=WIDE- WCHAN-COLUMN -o comm
). ps -o pid,wchan:42,cmd
ps -o pid,ruser=RealUser -o comm=Command
ps -o pid=X,comm=Y
is apparently different on various systems, some recognize the comma as column separator, others take it as part of the column header. -o
to disambiguate. ps -o pid= -o comm=
c | Show the true command name (executable file rather than argv value), args format keyword becomes comm . |
--cols n | Set screen width. |
--columns n | Set screen width. |
--cumulative | Include some dead child process data (as a sum with the parent). |
e | Show the environment after the command. |
f | ASCII art process hierarchy (forest). |
--forest | ASCII art process tree. |
h | No header. (or, one header per screen in the BSD personality). The h option is problematic. Standard BSD ps uses this option to print a header on each page of output, but older Linux ps uses this option to totally disable the header. This version of ps follows the Linux usage of not printing the header unless the BSD personality has been selected, in which case it prints a header on each page of output. Regardless of the current personality, you can use the long options --headers and --no-headers to enable printing headers each page or disable headers entirely, respectively. |
-H | Show process hierarchy (forest). |
--headers | Repeat header lines, one per page of output. |
k spec , --sort spec | Specify sorting order with a multi-letter format specifier. The syntax is [+|-]key[,[+|-]key[,…]] . Default is order in increasing order (number or lexicographically). For example: ps jax --sort=uid,-ppid,+pid |
--lines n | Set screen height. |
n | Force numeric output for wchan and user format specifiers, including all types of UID and GID. |
--no-headers | Print no header line at all. --no-heading is an alias for this option. |
O order | Sorting order (overloaded). The BSD O option can act like -O (user-defined output format with some common fields predefined) or can be used to specify sort order. Heuristics are used to determine the behavior of this option. To ensure that the desired behavior is obtained (sorting or formatting), specify the option in some other way (e.g. with -O or --sort ). |
--rows n | Set screen height. |
S | Sum up some information, such as CPU usage, from dead child processes into their parent. This is useful for examining a system where a parent process repeatedly forks off short-lived children to do work. |
w | Wide output. Use this option twice for unlimited width. |
-w | Wide output. Use this option twice for unlimited width. |
--width n | Set screen width. |
e
to print the process' environment. -p $$
selects the current process. -o cmd
selects a minimal set of columns. tr ' ' '\n'
so that each environment variable's name and value is printed on a separated line: $ ps -p $$ -o cmd e --no-headers | tr ' ' '\n' Debian ~/github/temp/temp ps -p $$ -o cmd e --no-headers | tr ' ' '\n' -bash HOSTTYPE=x86_64 LANG=en_US.UTF-8 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib TERM=xterm-256color HOME=/home/rene USER=rene LOGNAME=rene SHELL=/bin/bash …
H | Show threads as if they were processes. |
-L | Show threads, possibly with LWP and NLWP columns. |
m , -m | Show threads after processes. See also the pending format specifier. |
-T | Show threads, possibly with SPID column. |
--help section | section is one of simple, list, output, threads, misc, or all (or short: s, l, o, t, m or a). |
--info | Print debugging info. |
L | List all format specifiers. See also --format , -o and o . |
V , -v or --version | Print the procps-ng version. |
-e
option shows every process. ps -e
-A
(apparently standing for all) is equivalent. ps f
. ps --pid $PPID ps -q $PPID
U
option (note: no hyphen), the process of the given user id or user name can be queried. # Showing my processes. # # id -u returns my user id # # U selects processes with the given user id. ps -o pid,ppid,cmd U$(id -u)
ps
can be invoked with the -o
option (user defined format) to specify which columns should be reported. pid
), Parent Process ID (ppid
) and command with all its name (arg
) ps -o pid,ppid,args
-o
is o
, the GNU long option is --format
. -o
can be changed with :n
: cmd
is specified to be 40, the width of the user column to be 15: ps -e -o cmd:40,user:15,time
cmd
. // // gcc change-command-name.c -o change-command-name // #include <stdio.h> #include <string.h> #include <unistd.h> int main(int argc, char** argv) { printf("go to another terminal and enter\n"); printf(" ps --pid %d -o comm=Process-Name,cmd\n", getpid()); printf("press any key\n"); getc(stdin); strncpy(*argv, "Changed process title", strlen(*argv)); *argv[strlen(*argv)] = '\0'; printf("I have changed to process title, execute the command again.\n"); printf("press any key\n"); getc(stdin); }
cmd
and comm
. cmd
and comm
. STAT
: the process state. An s
indicates a session leader, a +
that the process is part of a foreground process group. These attributes are related to job control (pressing Ctrl-Z or starting a process in the background &
). f
(which stands for forest), the parent child relationship between the processes can be displayed: ps f ps xaf
pstree
. ps -s
: signal