Skip to content
On this page

Linux_进程状态


标签:linux/进程  

Linux 的进程有五种状态:

  1. 运行态(Running):进程正在执行或者等待执行,占用 CPU 资源。
  2. 就绪态(Ready):进程具备执行的条件,但由于 CPU 资源有限,暂时无法执行。进程处于就绪态时等待调度,一旦获取到 CPU,就可以进入运行态。
  3. 阻塞态(Blocked):进程由于等待某个事件(如 I/O 操作、信号量等)而暂时无法执行。进程在此状态下会被阻塞,直到所等待的事件发生,进程才能被唤醒并进入就绪态。
  4. 创建态(Created):进程正在被创建,但尚未完全初始化。在创建过程中,进程进行一些初始化操作,如分配内存空间、加载可执行文件等。创建完成后,进程将转入就绪态。
  5. 终止态(Terminated):进程执行完毕或被终止,处于不可执行状态。在终止态下,进程所占用的资源将被释放,包括内存、文件描述符等。

生命周期:创建阶段 --> 就绪阶段 --> 运行阶段 --> 阻塞阶段 --> 终止阶段

  • 僵尸态(Zombie):子进程消亡而父进程没有回收子进程资源,子进程进入僵尸态。(僵尸态是多线程中的概念,不包含在五种基本状态里)。

查看进程状态:

  • 可以通过ps指令查看进程的状态

状态码, 粘贴自 man ps:

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

    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
    D    uninterruptible sleep (usually IO)
    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 grou

Last updated: