Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

htop: 进程状态意义 #157

Open
dushaoshuai opened this issue Nov 30, 2024 · 0 comments
Open

htop: 进程状态意义 #157

dushaoshuai opened this issue Nov 30, 2024 · 0 comments
Labels
draft Still only a draft Linux Linux Operating system Operating system

Comments

@dushaoshuai
Copy link
Owner

各工具文档中的进程状态

# man htop
STATE (S)
     The state of the process:
        S for sleeping
        I for idle (longer inactivity than sleeping on platforms that distinguish)
        R for running
        D for disk sleep (uninterruptible)
        Z for zombie (waiting for parent to read its exit status)
        T for traced or suspended (e.g by SIGTSTP)
        W for paging
# man top
S  --  Process Status
          The status of the task which can be one of:
              D = uninterruptible sleep
              I = idle
              R = running
              S = sleeping
              T = stopped by job control signal
              t = stopped by debugger during trace
              Z = zombie
          Tasks  shown  as  running  should  be  more  properly  thought  of  as ready to run  --  their
          task_struct is simply represented on the Linux run-queue.  Even without a  true  SMP  machine,
          you may see numerous tasks in this state depending on top's delay interval and nice value.
# 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)
               I    Idle kernel thread
               R    running or runnable (on run queue)
               S    interruptible sleep (waiting for an event to complete)
               T    stopped by job control signal
               t    stopped by debugger during the tracing
               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

进程状态转换

process_state

R [running or runnable (on run queue)]

进程处于就绪态或运行态。

S [interruptible sleep (waiting for an event to complete)]

可中断睡眠状态。进程正在等待某件事发生。进程可以被信号唤醒。

$ sleep 1000 &
[1] 21836
$ kill -15 21836
[1]+  Terminated              sleep 1000
$ jobs -l
$ sleep 1000 &
[1] 21848
$ kill -9 21848
[1]+  Killed                  sleep 1000
$ jobs -l
$

D [uninterruptible sleep (usually IO)]

不可中断睡眠状态。进程正在等待某件事发生。进程不能被信号唤醒。

T [stopped by job control signal]

$ yes > /dev/null
^Z
[1]+  Stopped                 yes > /dev/null
$ ps -o stat,cmd
STAT CMD
...
T    yes
...

t [stopped by debugger during the tracing]

正在被调试器追踪。

Z [for zombie (waiting for parent to read its exit status)]

进程已经退出,不再占用资源,但是父进程还没有读取其退出状态(通过 wait 等系统调用)。

See also

@dushaoshuai dushaoshuai added draft Still only a draft Linux Linux Operating system Operating system labels Nov 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
draft Still only a draft Linux Linux Operating system Operating system
Projects
None yet
Development

No branches or pull requests

1 participant