Linux进程状态码总结

在Linux中执行ps aux命令时,STAT列表示的是进程的状态。最近研究了一下进程状态码,这里做一个简单的总结。
下图是ps的manual中给出的信息,本文将分别介绍每个状态

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

R running or runnable (on run queue)
进程正在CPU上运行,或者在排队等待CPU
S interruptible sleep (waiting for an event to complete)
进程处于可打断的睡眠状态,在等待某些事件来打断睡眠状态(如硬件中断、进程等待的资源可获得、获得接收到某些信号等)
D uninterruptible sleep (usually IO)
进程处于睡眠不可打断的睡眠状态,发送信号并不能改变睡眠状态,通常是在等待某些IO操作完成(如等待设备驱动完成设备扫描)
T stopped by job control signal
进程执行终止,进程在接收到SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU中任意一个时会进入该状态,在终端中使用Ctrl^Z会使得正在运行的进程进入后台(发送的信号是SIGTSTP)
t stopped by debugger during the tracing
进程因为调试暂停了,比如调试器用ptrace()进行调试,进程暂停时就会进入这种状态
X dead (should never be seen)
进程已经死亡
Z defunct (“zombie”) process, terminated but not reaped by its parent
僵尸进程,进程已经结束运行,但是该进程的父进程还没有为它调用wait4()或者waitpid()。在wait调用之前内核不会丢弃已经结束运行的进程的数据,因为父进程可能需要这些数据。(和这个相关的一个概念是孤儿进程,指的是父进程先结束,子进程还在运行,子进程就变成了孤儿进程,由pid为1的init进程收养,其ppid会变成1)

< 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)
进程要求内核讲自己的部分内存维持在内存中,不要cache out到磁盘中
s is a session leader
该进程是所在会话的leader进程
l is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)
该进程包含多个线程
+ is in the foreground process group
运行在前台的进程,就是你直接在终端中执行命令并在当前终端等待其完成的进程

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值