【ps与top】进程状态码详解

  作者:zhanhailiang 日期:2013-03-13

可以通过ps aux查看某进程的当前状态如下:

bill@net:~$ ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0   2920  1820 ?        Ss   22:04   0:00 /sbin/init
root         2  0.0  0.0      0     0 ?        S    22:04   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    22:04   0:00 [ksoftirqd/0]
root         5  0.0  0.0      0     0 ?        S    22:04   0:00 [kworker/u:0]
root         6  0.0  0.0      0     0 ?        S    22:04   0:00 [migration/0]
root         7  0.0  0.0      0     0 ?        S    22:04   0:00 [migration/1]
root         9  0.0  0.0      0     0 ?        S    22:04   0:00 [ksoftirqd/1]
root        10  0.0  0.0      0     0 ?        S    22:04   0:01 [kworker/0:1]

其中STAT列表示进程状态,那么STAT又有哪些状态码?查看man手册,如下:

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.

我们知道top输出也包含进程状态码,如下:

bill@net:~$ top
 
top - 22:34:37 up 29 min,  3 users,  load average: 0.02, 0.26, 0.21
Tasks: 175 total,   1 running, 173 sleeping,   0 stopped,   1 zombie
Cpu(s):  3.9%us,  1.4%sy,  0.0%ni, 91.8%id,  2.8%wa,  0.0%hi,  0.1%si,  0.0%st
Mem:   2058720k total,  1093180k used,   965540k free,    89528k buffers
Swap:  2094076k total,        0k used,  2094076k free,   428768k cached
 
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 1096 root      20   0 61132  45m  12m S   16  2.3   0:41.75 Xorg
  789 root      20   0  3156  648  508 S    2  0.0   0:00.29 irqbalance
 1750 bill      20   0  184m  82m  29m S    2  4.1   0:39.73 compiz
 1855 bill      20   0 74348  16m  10m S    2  0.8   0:23.03 unity-panel-ser
 1933 bill      20   0 66796  16m  11m S    2  0.8   0:06.76 gnome-terminal
 2263 bill      20   0  398m 107m  41m S    2  5.3   0:14.80 chrome
 2527 bill      20   0  2628 1156  848 R    2  0.1   0:00.01 top
    1 root      20   0  2920 1820 1276 S    0  0.1   0:00.55 init
    2 root      20   0     0    0    0 S    0  0.0   0:00.00 kthreadd
    3 root      20   0     0    0    0 S    0  0.0   0:00.04 ksoftirqd/0
    5 root      20   0     0    0    0 S    0  0.0   0:00.66 kworker/u:0
    6 root      RT   0     0    0    0 S    0  0.0   0:00.00 migration/0

其中S列也表示进程状态,那么其各状态码又分别表示什么呢?查看man手册,如下:

S  --  Process Status
The status of the task which can be one of:
   'D' = uninterruptible sleep
   'R' = running
   'S' = sleeping
   'T' = traced or stopped
   'Z' = zombie
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值