<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ### 進程狀態 根據進程的定義,我們知道進程是代碼運行的實體,而進程有可能是正在運行的,也可能是已經停止的,這就是進程的狀態。 網上有人總結進程一共5種狀態,也有總結是8種,究竟應該怎么算呢,最好的方法還是看Linux源碼。進程狀態的定義在[fs/proc/array.c](https://github.com/torvalds/linux/blob/b6da0076bab5a12afb19312ffee41c95490af2a0/fs/proc/array.c)文件中。 ~~~ /* * The task state array is a strange "bitmap" of * reasons to sleep. Thus "running" is zero, and * you can test for combinations of others with * simple bit tests. */ static const char * const task_state_array[] = { "R (running)", /* 0 */ "S (sleeping)", /* 1 */ "D (disk sleep)", /* 2 */ "T (stopped)", /* 4 */ "t (tracing stop)", /* 8 */ "X (dead)", /* 16 */ "Z (zombie)", /* 32 */ }; ~~~ 這真的是Linux的源碼,可以看出進程一共7種狀態,含義也比較清晰,注意其中D(disk sleep)稱為不可中斷睡眠狀態(uninterruptible sleep)。 知道進程狀態本身沒什么 ### 進程狀態轉換 ![](https://box.kancloud.cn/2015-08-18_55d2f2e744a02.svg) [使用Ptrace](https://idea.popcount.org/2012-12-11-linux-process-states/) [include/linux/sched.h](https://github.com/torvalds/linux/blob/master/include%2Flinux%2Fsched.h) ~~~ struct task_struct { volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */ void *stack; atomic_t usage; unsigned int flags; /* per process flags, defined below */ unsigned int ptrace; ~~~ ### 查看狀態 通過`ps aux`可以看到進程的狀態。 O:進程正在處理器運行,這個狀態從來沒有見過. S:休眠狀態(sleeping) R:等待運行(runable)R Running or runnable (on run queue) 進程處于運行或就緒狀態 I:空閑狀態(idle) Z:僵尸狀態(zombie) T:跟蹤狀態(Traced) B:進程正在等待更多的內存頁 D: 不可中斷的深度睡眠,一般由IO引起,同步IO在做讀或寫操作時,cpu不能做其它事情,只能等待,這時進程處于這種狀態,如果程序采用異步IO,這種狀態應該就很少見到了 其中就緒狀態表示進程已經分配到除CPU以外的資源,等CPU調度它時就可以馬上執行了。運行狀態就是正在運行了,獲得包括CPU在內的所有資源。等待狀態表示因等待某個事件而沒有被執行,這時候不耗CPU時間,而這個時間有可能是等待IO、申請不到足夠的緩沖區或者在等待信號。 ### 狀態轉換 進程的運行過程也就是進程狀態轉換的過程。 例如就緒狀態的進程只要等到CPU調度它時就馬上轉為運行狀態,一旦它需要的IO操作還沒有返回時,進程狀態也就轉換成等待狀態。 進程狀態間轉換還有很多,這里不一一細敘,馬上去學習進程退出碼吧。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看