【ps与top】进程状态码详解
作者:zhanhailiang 日期:2013-03-13
可以通过ps aux查看某进程的当前状态如下:
ps auxUSER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMANDroot 1 0.0 0.0 2920 1820 ? Ss 22:04 0:00 /sbin/initroot 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输出也包含进程状态码,如下:
22:34:37 up 29 min, 3 users, load average: 0.02, 0.26, 0.21Tasks: 175 total, 1 running, 173 sleeping, 0 stopped, 1 zombieCpu(s): 3.9%us, 1.4%sy, 0.0%ni, 91.8%id, 2.8%wa, 0.0%hi, 0.1%si, 0.0%stMem: 2058720k total, 1093180k used, 965540k free, 89528k buffersSwap: 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 StatusThe status of the task which can be one of: 'D' = uninterruptible sleep 'R' = running 'S' = sleeping 'T' = traced or stopped 'Z' = zombie