2010年6月16日星期三

ps 进程状态:PROCESS STATE CODES(转)

转:http://www.blogger.com/post-create.g?blogID=987012886678252745

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:
<>
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

1、ps 的参数说明


ps 提供了很多的选项参数,常用的有以下几个:


l 长格式输出;

u 按用户名和启动时间的顺序来显示进程;

j 用任务格式来显示进程;

f 用树形格式来显示进程;


a 显示所有用户的所有进程(包括其它用户);

x 显示无控制终端的进程;

r 显示运行中的进程;

ww 避免详细参数被截断;


我们常用的选项是组合是 aux 或 lax,还有参数 f 的应用。


2、ps aux 或 lax 输出的解释


USER 进程的属主;

PID 进程的ID;

PPID 父进程;

%CPU 进程占用的CPU百分比;

%MEM 占用内存的百分比;

NI 进程的NICE值,数值大,表示较少占用CPU时间;

VSZ 进程虚拟大小;

RSS 驻留中页的数量;

TTY 终端ID

STAT 进程状态(有以下几种)


D 无法中断的休眠状态(通常 IO 的进程);

R 正在运行可中在队列中可过行的;

S 处于休眠状态;

T 停止或被追踪;

W 进入内存交换(从内核2.6开始无效);

X 死掉的进程(从来没见过);

Z 僵尸进程;


< 优先级高的进程

N 优先级较低的进程

L 有些页被锁进内存;

s 进程的领导者(在它之下有子进程);

l 多进程的(使用 CLONE_THREAD, 类似 NPTL pthreads);

+ 位于后台的进程组;

WCHAN 正在等待的进程资源;

START 启动进程的时间;

TIME 进程消耗CPU的时间;

COMMAND 命令的名称和参数;


3 使用ps格式输出来查看进程状态:
ps -eo user,stat..,cmd

user 用户名
uid 用户号
pid 进程号
ppid 父进程号
size 内存大小, Kbytes字节.
vsize 总虚拟内存大小, bytes字节(包含code+data+stack)
share 总共享页数
nice 进程优先级(缺省为0, 最大为-20)
priority(pri) 内核调度优先级
pmem 进程分享的物理内存数的百分比
trs 程序执行代码驻留大小
rss 进程使用的总物理内存数, Kbytes字节
time 进程执行起到现在总的CPU暂用时间
stat 进程状态
cmd(args) 执行命令的简单格式

例子:
查看当前系统进程的uid,pid,stat,pri, 以uid号排序.
ps -eo pid,stat,pri,uid –sort uid

查看当前系统进程的user,pid,stat,rss,args, 以rss排序.
ps -eo user,pid,stat,rss,args –sort rss

没有评论: