当前位置: 技术问答>linux和unix
如何编程获得系统休眠的任务数?
来源: 互联网 发布时间:2016-09-04
本文导语: 正在运行的数可以在/proc/stat里获得,休眠的感觉也应该在/proc 文件系统里,但不知道在哪个文件里获得,求教 | 不知道怎么编程获得。我知道的有关的命令: 1. top输出的第二行 Tasks: 166...
正在运行的数可以在/proc/stat里获得,休眠的感觉也应该在/proc 文件系统里,但不知道在哪个文件里获得,求教
|
不知道怎么编程获得。我知道的有关的命令:
1.
top输出的第二行 Tasks: 166 total, 1 running, 165 sleeping, 0 stopped, 0 zombie
2.
ps -Al的第二列
$ man ps
......
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.
3.
$ man proc
......
/proc/[pid]/stat
Status information about the process. This is used by ps(1).
It is defined in /usr/src/linux/fs/proc/array.c.
The fields, in order, with their proper scanf(3) format speci-
fiers, are:
pid %d The process ID.
comm %s The filename of the executable, in parentheses.
This is visible whether or not the executable is
swapped out.
state %c One character from the string "RSDZTW" where R is
running, S is sleeping in an interruptible wait, D
is waiting in uninterruptible disk sleep, Z is zom-
bie, T is traced or stopped (on a signal), and W is
paging.
1.
top输出的第二行 Tasks: 166 total, 1 running, 165 sleeping, 0 stopped, 0 zombie
2.
ps -Al的第二列
$ man ps
......
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.
3.
$ man proc
......
/proc/[pid]/stat
Status information about the process. This is used by ps(1).
It is defined in /usr/src/linux/fs/proc/array.c.
The fields, in order, with their proper scanf(3) format speci-
fiers, are:
pid %d The process ID.
comm %s The filename of the executable, in parentheses.
This is visible whether or not the executable is
swapped out.
state %c One character from the string "RSDZTW" where R is
running, S is sleeping in an interruptible wait, D
is waiting in uninterruptible disk sleep, Z is zom-
bie, T is traced or stopped (on a signal), and W is
paging.