ps会显示当前一系列进程的快照,如果想要重复的显示,请使用top
三种风格:
Unix风格,选项以-开头
BSD风格,选项不能以-开头
GNU长选项,选项以--开头
三种风格可以混着用,但是也会发生冲突
ps命令的作用其实是一个过滤器,根据条件,过滤出你想要的进程的信息,
并可以定制输出哪些信息,对输出排序,输出的格式等
-
打印所有进程信息
ps -ef
ps aux -
打印进程树
ps -ejH
ps axjf -
打印线程信息
ps -eLf
ps axms -
打印 real和effective ID 为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 -eopid,tt,user,fname,tmout,f,wchan -
打印进程ID为syslogd的进程
ps -C syslogd -o pid= -
打印PID为42的进程
ps -p 42 -o comm=
选择条件
-e,-A:打印所有进程
x:必须有个tty,和a合用,打印所有
a:只是你自己的,和x合用,打印所有
-C:根据命令名字选择
p,-p,--pid:ps -p "1 2" -p 3,4
U,-U,-u,--User:
输出格式
-F,-f:does full-format listing
-o,-O,--format:-o pid,format,state,tname,time,command
-l:long format
u:display user-oriented format
-H:show process hierarchy (forest)
--forest:ASCII art process tree
S:Sum up some information, such as CPU usage, from dead child processes into their parent.
--cumulative:include some dead child process data (as a sum with the parent)
This is useful for examining a system where a parent process repeatedly
forks off short-lived children to do work.
c:Show the true command name
e:Show the environment after the command
f:ASCII-art process hierarchy (forest)
h: No header
k spec:specify sorting order. Sorting syntax is [+|-]key[,[+|-]key[,...]]
Choose a multi-letter key from the STANDARD FORMATSPECIFIERS 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
--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
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.
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)
R Running or runnable (on run queue)
S Interruptible sleep (waiting for an event to complete)
T Stopped, either by a job control signal or because it is being traced.
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
ENVIRONMENT VARIABLES
网友评论