「ps」- 报告当前进程的快照(查看系统进程状态)

  LINUX MANUAL PAGES

常用命令

排除内核进程(即排除 pid 及 ppid 为 2 的进程):

# ps --ppid 2 -p 2 --deselect

过滤特定状态的进程,这里以运行(R)进程为例:

# ps -e -ostate,command | grep -E '^R'

查看在系统中的每个进程(标准语法):

# ps -e
# ps -ef
# ps -eF
# ps -ely

查看在系统中的每个进程(使用BSD语法):

# ps ax
# ps axu

打印进程树:

# ps -ejH
# ps axjf

获取线程信息:

# ps -eLf
# ps axms

获取安全信息:

# ps -eo euser,ruser,suser,fuser,f,comm,label
# ps axZ
# ps -eM

使用用户格式查看所有以ROOT运行的进程:

# ps -U root -u root u

以用户自定义格式查看所有进程:

# ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm
# ps axo stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm
# ps -Ao pid,tt,user,fname,tmout,f,wchan

只打印syslogd的进程号:

# ps -C syslogd -o pid=

只打印 PID=42 的进程名:

# ps -q 42 -o comm=

语法格式

ps [options]

命令描述

该命令显示所选的活跃进程的信息。如果你想要所选进程与显示信息的不断更新,可以使用top(1)命令。

该版本命令接受几种选项:

(1)UNIX,可以将选项放在一起,但是必须前缀横线。比如 ps -ef

(2)BSD,可以将选项放在一起,但是必须不使用前缀横线。比如 ps ef

(3)GNU long options,长选项,前缀两个横线。比如 ps –group root

可以自由混合不同类型选项,但是可能出现冲突。由于存在多种标准与实现,该版本为了兼容,所以有些选项同义(功能一致),

注意 ps -aux 与 ps aux 不同。在POSIX与UNIX标准中,ps -aux 打印所有属于用户 ‘x’ 的进程,此外打印所有由 -a 选择的进程。如果用户 ‘x’ 不存在,该命令可能将命令作为 ps aux 理解,而不是打印警告。该行为意图在辅助旧脚本及习惯中的过渡。该功能不可靠,可能发生改变,因此不应该依靠它。

默认,该命令选择与当前用户具有相同EUID(euid=EUID)与命令调用者关联到相同终端的所有进程。显示进程号(pid=PID)、关联进程的终端(tname=TTY)、以 [DD-]hh:mm:ss 格式显示的累计处理器时间(time=TIME)、执行文件名(ucmd=CMD)。默认输出未排序。

使用BSD风格选项将在默认显示中添加进程状态(stat=STAT)、命令行参数(args=COMMAND)而不是可执行文件名。可以使用PS_FORMAT环境变量覆盖。使用BSD风格选项也会改变进程选择,会包含在其他属于你的终端上的进程;或者说,将选择设置为排除其他用户所有或不在终端上的进程以外的进程。当选项被描述为“相同”时,没有考虑这些影响,因此 -M 将被视为与 Z 相同,如此类推(意思是当我们说两个选项“相同”,但是这只是说功能相同。这个“相同”中并不包含这些附加影响)。

以下所述除外,进程选择是累加的。默认选择会被丢弃,然后将被选进程添加到显示列表中。只要进程满足任何选择条件就会被显示。

命令选项

简单进程选择

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.

换句话说,该选项导致 ps 列出全部带有终端(tty)的进程,或者当与 x 选项共同使用时列出所有进程。
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
选择所有进程。

-a
选择所有进程,除了会话领导(man 2 getsid)和没有关联到终端的进程。

-d
选择所有进程,除了会话领导(Session Leader)

-N, –deselect
选择所有进程,除了那些满足特定条件的(否定选择)。

g
所有进程(真正的所有进程)。该选项已废弃,以后可能会移除。通常会隐含在 a 选项中,并且当在SunOS 4上操作才有用。
Really all, even session leaders. This flag is obsolete and may be discontinued in a future release. It is normally implied by the a flag, and is only useful when operating in the sunos4 personality.

T
选择所有关联到当前终端的进程。与不带参数的 t 选项一致。

r
将选择限制为只有正在运行的进程

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.

通过列选择进程

这些选项接受单个参数,格式为以逗号分隔(ps -p 3,4)或空格分隔(ps -p “1 2″)的列表,并且可以使用多次(ps -p “1 2” -p 3,4)

-123, 123
等同于 –pid 123

p pidlist, -p pidlist, –pid pidlist
通过进程号选择进程,选择出现在 pidlist 中的进程。

-C cmdlist
通过命令名选择进程。选择可执行文件名出现在 cmdlist 中的进程。

-G grplist, –Group grplist
通过实际组号(RGID)或实际组名选择进程。该选项选择实际组号(RGID)或实际组名在 grplist 中的进程。实际组号标识出创建进程的用户的组,参考 getgid(2) 手册。

-g grplist
通过会话或有效组名。许多标准指定按会话选择进程,但是通过有效组选择进程是符合逻辑的行为(其他几个操作系统使用的)。当列表(grplist)全是数字时,该 ps 将通过会话选择进程。只有当指定某些组名时,组号数字才会有效。参考 -s 与 –group 选项。

–group grplist
通过有效组号(EGID)或有效组名选择进程。该选项将选择有效组号(EGID)或有效组名在 grplist 中的进程。有效组号描述进程使用哪个组的文件访问权限(参考 getegied(2) 手册)。选项 -g 通常可以替代 –group 选项。

–ppid pidlist
通过父进程号(PPID)选择进程。该选项选择父进程号在 pidlist 中的进程。即选择在 pidlist 中列出来的那些进程的子进程。

q pidlist, -q pidlist, –quick-pid pidlist
通过进程号(PID)选择进程(快速模式)。该选项选择进程号出现在 pidlist 中的进程。通过该选项,ps 仅为在 pidlist 中列出来的进程号读取必要信息,并且不会应用附加过滤规则。进程号的顺序是未被排序的、保留原状的(即命令行指定的顺序)。在该模式下,不允许使用其他选择选项,排序,树形列表。

-s sesslist, –sid sesslist
通过会话号(Session ID)选择进程。选择会话号在 sesslist 中的进程。

t ttylist
通过 tty 选择进程。基本与 -t 和 –tty 相同,但是可以指定空 ttylist 以表示与 ps 关联的终端。与使用空 ttylist 的 t 选项相比,使用 T 选项比更干净(好看)。

-t ttylist, –tty ttylist
通过终端(tty)选择进程。在 ttylist 中指定终端,选择与这些终端关联的进程。可以用多种格式指定终端(ttys,screens for text output):/dev/ttyS1, ttyS1, S1。使用简单的“-”以选择没有与终端关联的进程。

-U userlist, –User userlist
通过实际用户号(RUID)或实际用户名选择进程。该选项选择实际用户号或实际用户名在 userlist 中的进程。实际用户号标识出创建进程的用户,参考 getuid(2) 手册。

U userlist, -u userlist, –user userlist
通过有效用户号(EUID)或有效用户名选择进程。该选项选择有效用户号或有效用户名在 userlist 中的进程。有效用户号标识出进程使用的哪个用户的文件访问权限(参考 geteuuid(2) 手册)。

控制输出格式

这些选项用于控制 ps 显示信息。如果特征(PERSONALITY)设置不同,命令输出也会有所不同。

-f
显示完整格式列表。该选项可以与其他 UNIX 风格选项结合,以添加附加的列。该选项也会打印命令参数。当与 -L 选项共同使用时,将添加 NLWP(Number of Threads)与 LWP(Thread ID)列。参考:选项 c ,格式化关键字 args,格式化关键字 comm(参考「标准格式说明符」部分)。

-F
额外的完整格式。参考 -f 选项,隐含 -F。

-l
长格式。选项 -y 通常对此很有用。

-y
不显示标志字段(F);用 RSS 代替 ADDR 字段。该选项只能与 -l 使用。

-c
为 -l 选项显示不同的调度器信息。

o format, -o format, –format format
使用用户定义的格式。format 是单个参数,使用空白分割或逗号分隔的列表,该选项提供选择独特输出列的方式。可识别的关键字参考「标准格式说明符」部分。

可以根据需要修改输出的头部(ps -o pid,ruser=RealUser -o comm=Command)。如果所有列头为空,则会隐藏头部行的输出。

对于宽标题,列宽将根据需要增加;这可以用于增加列宽,比如 WCHAN(ps -o pid,wchan=WIDE-WCHAN-COLUMN -o comm)。也支持明确的列宽控制(ps opid,wchan:42,cmd)。

ps -o pid=X,comm=Y 的行为会随着特征(PERSONALITY)设置而改变;输出可能是名为 X,comm=Y 的列,或者名为 X 与 Y 的两个列。有疑问时可以使用多次 -o 选项。使用 PS_FORMAT 环境变量指定期望的默认格式;DefSysV 与 DefBSD 是宏,用于选择默认 UNIX 或 BSD 列。

-O format
类似于 -o 选项,但是会预加载某些默认列。等同于 -o pid,format,state,tname,time,command 或 -o pid,format,tname,time,cmd 组合。

O format
是预加载的 o 选项(过载的)。BSD 的 O 选项行为像 -O(带有某些常见预定义字段的用户定义的输出格式),或者用于指定排序顺序。使用启发式用于确定此选项的行为。为了确保得到期望行为(排序或格式化),使用其他方式指定选项(例如 -O 或 –sort)。与 BSD 特征在一起,当用作格式化选项时,它与 -O 相同。

j
显示 BSD 作业控制(Job Control)格式。

-j
显示作业(Job)格式

l
显示 BSD 长格式

s
显示信号格式。

u
显示面向用户格式。

v
显示虚拟内存格式。

X
寄存器格式。

–context
显示安全上下文格式(用于 SELinux)。

Z, -M
在输出中添加安全数据的列(用于 SELinux)。

输出修饰符(OUTPUT MODIFIERS)

c Show the true command name. This is derived from the name of the executable file, rather than from the argv value. Command arguments and any modifications to them are thus not shown. This option effectively turns the args format keyword into the comm format keyword; it is useful with the -f format option and with the various BSD-style format options, which all normally display the command arguments. See the -f option, the format keyword args, and the format keyword 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 Specify sorting order. Sorting syntax is [+|-]key[,[+|-]key[,…]]. Choose a multi-letter key from the STANDARD FORMAT SPECIFIERS section. The “+” is optional since default direction is increasing numerical or lexicographic order. Identical to –sort.

Examples:

ps jaxkuid,-ppid,+pid

ps axk comm o comm,args

ps kstart_time -ef

–lines n
Set screen height.

n Numeric output for WCHAN and USER (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).

For sorting, obsolete BSD O option syntax is O[+|-]k1[,[+|-]k2[,…]]. It orders the processes listing according to the multilevel sort specified by the sequence of one-letter short keys k1,k2, … described in the OBSOLETE SORT KEYS section below. The “+” is currently optional, merely re-iterating the default direction on a key, but may help to distinguish an O sort from an O format. The “-” reverses direction only on the key it precedes.

–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.

–sort spec
Specify sorting order. Sorting syntax is [+|-]key[,[+|-]key[,…]]. Choose a multi-letter key from the STANDARD FORMAT SPECIFIERS section. The “+” is optional since default direction is increasing numerical or lexicographic order. Identical to k. For example: ps jax –sort=uid,-ppid,+pid

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.

线程显示(THREAD DISPLAY)

H
Show threads as if they were processes.

-L
Show threads, possibly with LWP and NLWP columns.

m
Show threads after processes.

-m
Show threads after processes.

-T
Show threads, possibly with SPID column.

其他选项

–help section
显示帮助信息。参数 section 可以是 simple, list, output, threads, misc, all 之一。参数可以缩短为:s, l, o, t, m, a

–info
显示调试信息

L
列出所有格式说明符。参考「标准格式说明符」部分

V, -V, –version
显示 procps-ng 版本信息。

注意事项

This ps works by reading the virtual files in /proc. This ps does not need to be setuid kmem or have any privileges to run. Do not give this ps any special permissions.

CPU usage is currently expressed as the percentage of time spent running during the entire lifetime of a process. This is not ideal, and it does not conform to the standards that ps otherwise conforms to. CPU usage is unlikely to add up to exactly 100%.

The SIZE and RSS fields don’t count some parts of a process including the page tables, kernel stack, struct thread_info, and struct task_struct. This is usually at least 20 KiB of memory that is always resident. SIZE is the virtual size of the process (code+data+stack).

Processes marked <defunct> are dead processes (so-called “zombies”) that remain because their parent has not destroyed them properly. These processes will be destroyed by init(8) if the parent process exits.

If the length of the username is greater than the length of the display column, the username will be truncated. See the -o and -O formatting options to customize length.

Commands options such as ps -aux are not recommended as it is a confusion of two different standards. According to the POSIX and UNIX standards, the above command asks to display all processes with a TTY (generally the commands users are running) plus all processes owned by a user named “x”. If that user doesn’t exist, then ps will assume you really meant “ps aux”.

PROCESS FLAGS

The sum of these values is displayed in the “F” column, which is provided by the flags output specifier:

1 forked but didn’t exec

4 used super-user privileges

PROCESS STATE CODES

Here are the different values that the s, stat and state output specifiers (header “STAT” or “S”) will display to describe the state of a process:

D uninterruptible sleep (usually IO)

I Idle kernel thread

R running or runnable (on run queue)

S interruptible sleep (waiting for an event to complete)

T stopped by job control signal

t stopped by debugger during the tracing

W paging (not valid since the 2.6.xx kernel)

X dead (should never be seen)

Z defunct (“zombie”) process, terminated but not reaped by its parent

For BSD formats and when the stat keyword is used, additional characters may be displayed:

< high-priority (not nice to other users)

N low-priority (nice to other users)

L has pages locked into memory (for real-time and custom IO)

s is a session leader

l is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)

+ is in the foreground process group

OBSOLETE SORT KEYS

These keys are used by the BSD O option (when it is used for sorting). The GNU –sort option doesn’t use these keys, but the specifiers described below in the STANDARD FORMAT SPECIFIERS section. Note that the values used in sorting are the internal values ps uses and not the “cooked” values used in some of the output format fields (e.g. sorting on tty will sort into device number, not according to the terminal name displayed). Pipe ps output into the sort(1) command if you want to sort the cooked values.

KEY LONG DESCRIPTION

c cmd simple name of executable

C pcpu cpu utilization

f flags flags as in long format F field

g pgrp process group ID

G tpgid controlling tty process group ID

j cutime cumulative user time

J cstime cumulative system time

k utime user time

m min_flt number of minor page faults

M maj_flt number of major page faults

n cmin_flt cumulative minor page faults

N cmaj_flt cumulative major page faults

o session session ID

p pid process ID

P ppid parent process ID

r rss resident set size

R resident resident pages

s size memory size in kilobytes

S share amount of shared pages

t tty the device number of the controlling tty

T start_time time process was started

U uid user ID number

u user user name

v vsize total VM size in KiB

y priority kernel scheduling priority

AIX FORMAT DESCRIPTORS

This ps supports AIX format descriptors, which work somewhat like the formatting codes of printf(1) and printf(3). For example, the normal default output can be produced with this: ps -eo “%p %y %x %c”. The NORMAL codes are described in the next section.

CODE NORMAL HEADER

%C pcpu %CPU

%G group GROUP

%P ppid PPID

%U user USER

%a args COMMAND

%c comm COMMAND

%g rgroup RGROUP

%n nice NI

%p pid PID

%r pgid PGID

%t etime ELAPSED

%u ruser RUSER

%x time TIME

%y tty TTY

%z vsz VSZ

标准格式说明符(STANDARD FORMAT SPECIFIERS)

Here are the different keywords that may be used to control the output format (e.g. with option -o) or to sort the selected processes with the GNU-style –sort option.

For example: ps -eo pid,user,args –sort user

This version of ps tries to recognize most of the keywords used in other implementations of ps.

The following user-defined format specifiers may contain spaces: args, cmd, comm, command, fname, ucmd, ucomm, lstart, bsdstart, start.

Some keywords may not be available for sorting.

CODE HEADER DESCRIPTION

%cpu %CPU cpu utilization of the process in “##.#” format. Currently, it is the CPU time used divided by the time the process has been running (cputime/realtime ratio), expressed as a percentage. It will not add up to 100% unless you are lucky. (alias pcpu).

%mem %MEM ratio of the process’s resident set size to the physical memory on the machine, expressed as a percentage. (alias pmem).

args COMMAND command with all its arguments as a string. Modifications to the arguments may be shown. The output in this column may contain spaces. A process marked <defunct> is partly dead, waiting to be fully destroyed by its parent. Sometimes the process args will be unavailable; when this happens, ps will instead print the executable name in brackets. (alias cmd, command). See also the comm format keyword, the -f option, and the c option.
When specified last, this column will extend to the edge of the display. If ps can not determine display width, as when output is redirected (piped) into a file or another command, the output width is undefined (it may be 80, unlimited, determined by the TERM variable, and so on). The COLUMNS environment variable or –cols option may be used to exactly determine the width in this case. The w or -w option may be also be used to adjust width.

blocked BLOCKED mask of the blocked signals, see signal(7). According to the width of the field, a 32 or 64-bit mask in hexadecimal format is displayed. (alias sig_block, sigmask).

bsdstart START time the command started. If the process was started less than 24 hours ago, the output format is ” HH:MM”, else it is ” Mmm:SS” (where Mmm is the three letters of the month). See also lstart, start, start_time, and stime.

bsdtime TIME accumulated cpu time, user + system. The display format is usually “MMM:SS”, but can be shifted to the right if the process used more than 999 minutes of cpu time.

c C processor utilization. Currently, this is the integer value of the percent usage over the lifetime of the process. (see %cpu).

caught CAUGHT mask of the caught signals, see signal(7). According to the width of the field, a 32 or 64 bits mask in hexadecimal format is displayed. (alias sig_catch, sigcatch).

cgname CGNAME display name of control groups to which the process belongs.

cgroup CGROUP display control groups to which the process belongs.

class CLS scheduling class of the process. (alias policy, cls). Field’s possible values are:

– not reported

TS SCHED_OTHER

FF SCHED_FIFO

RR SCHED_RR

B SCHED_BATCH

ISO SCHED_ISO

IDL SCHED_IDLE

DLN SCHED_DEADLINE

? unknown value

cls CLS scheduling class of the process. (alias policy, cls). Field’s possible values are:

– not reported

TS SCHED_OTHER

FF SCHED_FIFO

RR SCHED_RR

B SCHED_BATCH

ISO SCHED_ISO

IDL SCHED_IDLE

DLN SCHED_DEADLINE

? unknown value

cmd CMD see args. (alias args, command).

comm COMMAND command name (only the executable name). Modifications to the command name will not be shown. A process marked <defunct> is partly dead, waiting to be fully destroyed by its parent. The output in this column may contain spaces. (alias ucmd, ucomm). See also the args format keyword, the -f option, and the c option.
When specified last, this column will extend to the edge of the display. If ps can not determine display width, as when output is redirected (piped) into a file or another command, the output width is undefined (it may be 80, unlimited, determined by the TERM variable, and so on). The COLUMNS environment variable or –cols option may be used to exactly determine the width in this case. The w or -w option may be also be used to adjust width.

command COMMAND See args. (alias args, command).

cp CP per-mill (tenths of a percent) CPU usage. (see %cpu).

cputime TIME cumulative CPU time, “[DD-]hh:mm:ss” format. (alias time).

cputimes TIME cumulative CPU time in seconds (alias times).

drs DRS data resident set size, the amount of physical memory devoted to other than executable code.

egid EGID effective group ID number of the process as a decimal integer. (alias gid).

egroup EGROUP effective group ID of the process. This will be the textual group ID, if it can be obtained and the field width permits, or a decimal representation otherwise. (alias group).

eip EIP instruction pointer.

esp ESP stack pointer.

etime ELAPSED elapsed time since the process was started, in the form [[DD-]hh:]mm:ss.

etimes ELAPSED elapsed time since the process was started, in seconds.

euid EUID effective user ID (alias uid).

euser EUSER effective user name. This will be the textual user ID, if it can be obtained and the field width permits, or a decimal representation otherwise. The n option can be used to force the decimal representation. (alias uname, user).

f F flags associated with the process, see the PROCESS FLAGS section. (alias flag, flags).

fgid FGID filesystem access group ID. (alias fsgid).

fgroup FGROUP filesystem access group ID. This will be the textual group ID, if it can be obtained and the field width permits, or a decimal representation otherwise. (alias fsgroup).

flag F see f. (alias f, flags).

flags F see f. (alias f, flag).

fname COMMAND first 8 bytes of the base name of the process’s executable file. The output in this column may contain spaces.

fuid FUID filesystem access user ID. (alias fsuid).

fuser FUSER filesystem access user ID. This will be the textual user ID, if it can be obtained and the field width permits, or a decimal representation otherwise.

gid GID see egid. (alias egid).

group GROUP see egroup. (alias egroup).

ignored IGNORED mask of the ignored signals, see signal(7). According to the width of the field, a 32 or 64 bits mask in hexadecimal format is displayed. (alias sig_ignore, sigignore).

ipcns IPCNS Unique inode number describing the namespace the process belongs to. See namespaces(7).

label LABEL security label, most commonly used for SELinux context data. This is for the Mandatory Access Control (“MAC”) found on high-security systems.

lstart STARTED time the command started. See also bsdstart, start, start_time, and stime.

lsession SESSION displays the login session identifier of a process, if systemd support has been included.

luid LUID displays Login ID associated with a process.

lwp LWP light weight process (thread) ID of the dispatchable entity (alias spid, tid). See tid for additional information.

lxc LXC The name of the lxc container within which a task is running. If a process is not running inside a container, a dash (‘-‘) will be shown.

machine MACHINE displays the machine name for processes assigned to VM or container, if systemd support has been included.

maj_flt MAJFLT The number of major page faults that have occurred with this process.

min_flt MINFLT The number of minor page faults that have occurred with this process.

mntns MNTNS Unique inode number describing the namespace the process belongs to. See namespaces(7).

netns NETNS Unique inode number describing the namespace the process belongs to. See namespaces(7).

ni NI nice value. This ranges from 19 (nicest) to -20 (not nice to others), see nice(1). (alias nice).

nice NI see ni.(alias ni).

nlwp NLWP number of lwps (threads) in the process. (alias thcount).

numa NUMA The node assocated with the most recently used processor. A -1 means that NUMA information is unavailable.

nwchan WCHAN address of the kernel function where the process is sleeping (use wchan if you want the kernel function name). Running tasks will display a dash (‘-‘) in this column.

ouid OWNER displays the Unix user identifier of the owner of the session of a process, if systemd support has been included.

pcpu %CPU see %cpu. (alias %cpu).

pending PENDING mask of the pending signals. See signal(7). Signals pending on the process are distinct from signals pending on individual threads. Use the m option or the -m option to see both. According to the width of the field, a 32 or 64 bits mask in hexadecimal format is displayed. (alias sig).

pgid PGID process group ID or, equivalently, the process ID of the process group leader. (alias pgrp).

pgrp PGRP see pgid. (alias pgid).

pid PID a number representing the process ID (alias tgid).

pidns PIDNS Unique inode number describing the namespace the process belongs to. See namespaces(7).

pmem %MEM see %mem. (alias %mem).

policy POL scheduling class of the process. (alias class, cls). Possible values are:

– not reported

TS SCHED_OTHER

FF SCHED_FIFO

RR SCHED_RR

B SCHED_BATCH

ISO SCHED_ISO

IDL SCHED_IDLE

DLN SCHED_DEADLINE

? unknown value

ppid PPID parent process ID.

pri PRI priority of the process. Higher number means lower priority.

psr PSR processor that process is currently assigned to.

rgid RGID real group ID.

rgroup RGROUP real group name. This will be the textual group ID, if it can be obtained and the field width permits, or a decimal representation otherwise.

rss RSS resident set size, the non-swapped physical memory that a task has used (in kiloBytes). (alias rssize, rsz).

rssize RSS see rss. (alias rss, rsz).

rsz RSZ see rss. (alias rss, rssize).

rtprio RTPRIO realtime priority.

ruid RUID real user ID.

ruser RUSER real user ID. This will be the textual user ID, if it can be obtained and the field width permits, or a decimal representation otherwise.

s S minimal state display (one character). See section PROCESS STATE CODES for the different values. See also stat if you want additional information displayed. (alias state).

sched SCH scheduling policy of the process. The policies SCHED_OTHER (SCHED_NORMAL), SCHED_FIFO, SCHED_RR, SCHED_BATCH, SCHED_ISO, SCHED_IDLE and SCHED_DEADLINE are respectively displayed as 0, 1, 2, 3, 4, 5 and 6.

seat SEAT displays the identifier associated with all hardware devices assigned to a specific workplace, if systemd support has been included.

sess SESS session ID or, equivalently, the process ID of the session leader. (alias session, sid).

sgi_p P processor that the process is currently executing on. Displays “*” if the process is not currently running or runnable.

sgid SGID saved group ID. (alias svgid).

sgroup SGROUP saved group name. This will be the textual group ID, if it can be obtained and the field width permits, or a decimal representation otherwise.

sid SID see sess. (alias sess, session).

sig PENDING see pending. (alias pending, sig_pend).

sigcatch CAUGHT see caught. (alias caught, sig_catch).

sigignore IGNORED see ignored. (alias ignored, sig_ignore).

sigmask BLOCKED see blocked. (alias blocked, sig_block).

size SIZE approximate amount of swap space that would be required if the process were to dirty all writable pages and then be swapped out. This number is very rough!

slice SLICE displays the slice unit which a process belongs to, if systemd support has been included.

spid SPID see lwp. (alias lwp, tid).

stackp STACKP address of the bottom (start) of stack for the process.

start STARTED time the command started. If the process was started less than 24 hours ago, the output format is “HH:MM:SS”, else it is ” Mmm dd” (where Mmm is a three-letter month name). See also lstart, bsdstart, start_time, and stime.

start_time START starting time or date of the process. Only the year will be displayed if the process was not started the same year ps was invoked, or “MmmDD” if it was not started the same day, or “HH:MM” otherwise. See also bsdstart, start, lstart, and stime.

stat STAT multi-character process state. See section PROCESS STATE CODES for the different values meaning. See also s and state if you just want the first character displayed.

state S see s. (alias s).

suid SUID saved user ID. (alias svuid).

supgid SUPGID group ids of supplementary groups, if any. See getgroups(2).

supgrp SUPGRP group names of supplementary groups, if any. See getgroups(2).

suser SUSER saved user name. This will be the textual user ID, if it can be obtained and the field width permits, or a decimal representation otherwise. (alias svuser).

svgid SVGID see sgid. (alias sgid).

svuid SVUID see suid. (alias suid).

sz SZ size in physical pages of the core image of the process. This includes text, data, and stack space. Device mappings are currently excluded; this is subject to change. See vsz and rss.

tgid TGID a number representing the thread group to which a task belongs (alias pid). It is the process ID of the thread group leader.

thcount THCNT see nlwp. (alias nlwp). number of kernel threads owned by the process.

tid TID the unique number representing a dispatchable entity (alias lwp, spid). This value may also appear as: a process ID (pid); a process group ID (pgrp); a session ID for the session leader (sid); a thread group ID for the thread group leader (tgid); and a tty process group ID for the process group leader (tpgid).

time TIME cumulative CPU time, “[DD-]HH:MM:SS” format. (alias cputime).

times TIME cumulative CPU time in seconds (alias cputimes).

tname TTY controlling tty (terminal). (alias tt, tty).

tpgid TPGID ID of the foreground process group on the tty (terminal) that the process is connected to, or -1 if the process is not connected to a tty.

trs TRS text resident set size, the amount of physical memory devoted to executable code.

tt TT controlling tty (terminal). (alias tname, tty).

tty TT controlling tty (terminal). (alias tname, tt).

ucmd CMD see comm. (alias comm, ucomm).

ucomm COMMAND see comm. (alias comm, ucmd).

uid UID see euid. (alias euid).

uname USER see euser. (alias euser, user).

unit UNIT displays unit which a process belongs to, if systemd support has been included.

user USER see euser. (alias euser, uname).

userns USERNS Unique inode number describing the namespace the process belongs to. See namespaces(7).

utsns UTSNS Unique inode number describing the namespace the process belongs to. See namespaces(7).

uunit UUNIT displays user unit which a process belongs to, if systemd support has been included.

vsize VSZ see vsz. (alias vsz).

vsz VSZ virtual memory size of the process in KiB (1024-byte units). Device mappings are currently excluded; this is subject to change. (alias vsize).

wchan WCHAN name of the kernel function in which the process is sleeping, a “-” if the process is running, or a “*” if the process is multi-threaded and ps is not displaying threads.

附加说明

特征设置(PERSONALITY)

390 like the OS/390 OpenEdition ps
aix like AIX ps
bsd like FreeBSD ps (totally non-standard)
compaq like Digital Unix ps
debian like the old Debian ps
digital like Tru64 (was Digital Unix, was OSF/1) ps
gnu like the old Debian ps
hp like HP-UX ps
hpux like HP-UX ps
irix like Irix ps
linux *** recommended ***
old like the original Linux ps (totally non-standard)
os390 like OS/390 Open Edition ps
posix standard
s390 like OS/390 Open Edition ps
sco like SCO ps
sgi like Irix ps
solaris2 like Solaris 2+ (SunOS 5) ps
sunos4 like SunOS 4 (Solaris 1) ps (totally non-standard)
svr4 standard
sysv standard
tru64 like Tru64 (was Digital Unix, was OSF/1) ps
unix standard
unix95 standard
unix98 standard

环境变量

The following environment variables could affect ps:

COLUMNS

Override default display width.

LINES

Override default display height.

PS_PERSONALITY

Set to one of posix, old, linux, bsd, sun, digital… (see section PERSONALITY below).

CMD_ENV

Set to one of posix, old, linux, bsd, sun, digital… (see section PERSONALITY below).

I_WANT_A_BROKEN_PS

Force obsolete command line interpretation.

LC_TIME

Date format.

PS_COLORS

Not currently supported.

PS_FORMAT

Default output format override. You may set this to a format string of the type used for the -o option. The DefSysV and DefBSD values are particularly useful.

POSIXLY_CORRECT

Don’t find excuses to ignore bad “features”.

POSIX2

When set to “on”, acts as POSIXLY_CORRECT.

UNIX95

Don’t find excuses to ignore bad “features”.

_XPG

Cancel CMD_ENV=irix non-standard behavior.

In general, it is a bad idea to set these variables. The one exception is CMD_ENV or PS_PERSONALITY, which could be set to Linux for normal systems. Without that setting, ps follows the useless and bad parts of the Unix98 standard.

STANDARDS

This ps conforms to:

1 Version 2 of the Single Unix Specification
2 The Open Group Technical Standard Base Specifications, Issue 6
3 IEEE Std 1003.1, 2004 Edition
4 X/Open System Interfaces Extension [UP XSI]
5 ISO/IEC 9945:2003

相关手册

pgrep(1), pstree(1), top(1), proc(5).

参考文献

man 1 ps, Version 2 3.3.15-2
process – Can ps display only non kernel processes on Linux? – Unix & Linux Stack Exchange
command line – How do I filter by STAT with ps? – Unix & Linux Stack Exchange