中文字幕精品亚洲无线码二区,国产黄a三级三级三级看三级,亚洲七七久久桃花影院,丰满少妇被猛烈进入,国产小视频在线观看网站

每天一個linux命(ming)令(41):ps命(ming)令

Linux中的(de)(de)ps命(ming)令是Process Status的(de)(de)縮寫。ps命(ming)令用來列出(chu)系(xi)統中當前運行(xing)的(de)(de)那(nei)些進程(cheng)(cheng)。ps命(ming)令列出(chu)的(de)(de)是當前那(nei)些進程(cheng)(cheng)的(de)(de)快(kuai)照,就(jiu)是執行(xing)ps命(ming)令的(de)(de)那(nei)個時刻的(de)(de)那(nei)些進程(cheng)(cheng),如果想要(yao)動態(tai)的(de)(de)顯(xian)示進程(cheng)(cheng)信息,就(jiu)可以使用top命(ming)令。

要(yao)(yao)對進(jin)(jin)程(cheng)進(jin)(jin)行(xing)監測和控制,首先必(bi)須要(yao)(yao)了解當(dang)前進(jin)(jin)程(cheng)的情況(kuang),也就是(shi)需要(yao)(yao)查看(kan)(kan)當(dang)前進(jin)(jin)程(cheng),而 ps 命(ming)令(ling)就是(shi)最基本同(tong)時也是(shi)非(fei)常強大的進(jin)(jin)程(cheng)查看(kan)(kan)命(ming)令(ling)。使用(yong)該(gai)命(ming)令(ling)可以(yi)確定有哪些進(jin)(jin)程(cheng)正在運行(xing)和運行(xing)的狀態、進(jin)(jin)程(cheng)是(shi)否結束、進(jin)(jin)程(cheng)有沒有僵死、哪些進(jin)(jin)程(cheng)占用(yong)了過(guo)(guo)多(duo)的資源等(deng)等(deng)。總之大部分信息(xi)都是(shi)可以(yi)通過(guo)(guo)執行(xing)該(gai)命(ming)令(ling)得(de)到(dao)的。

ps 為我們提(ti)供了進程的(de)一(yi)次性的(de)查看,它(ta)所提(ti)供的(de)查看結(jie)果并不動態連續的(de);如果想對進程時間監控,應該用 top 工具。

kill 命(ming)令用于殺(sha)死進程(cheng)。

linux上進(jin)程有(you)5種狀(zhuang)態(tai): 

1. 運(yun)(yun)行(xing)(正(zheng)在運(yun)(yun)行(xing)或(huo)在運(yun)(yun)行(xing)隊(dui)列中(zhong)等(deng)待) 

2. 中斷(duan)(休眠中, 受(shou)阻, 在等待某個條件的形成(cheng)或接受(shou)到(dao)信號) 

3. 不可中(zhong)斷(duan)(收到信(xin)號不喚醒(xing)和不可運行, 進程必須等待直到有中(zhong)斷(duan)發(fa)生(sheng)) 

4. 僵(jiang)死(進程已(yi)終止, 但進程描(miao)述符存在, 直到(dao)父(fu)進程調用(yong)(yong)wait4()系統(tong)調用(yong)(yong)后(hou)釋放) 

5. 停止(進程收到(dao)SIGSTOP, SIGSTP, SIGTIN, SIGTOU信號(hao)后停止運(yun)行運(yun)行) 

ps工具(ju)標識(shi)進(jin)程的5種狀態(tai)碼: 

D 不可中(zhong)斷 uninterruptible sleep (usually IO) 

R 運行 runnable (on run queue) 

S 中斷 sleeping 

T 停(ting)止(zhi) traced or stopped 

Z 僵死 a defunct (”zombie”) process 

1.命(ming)令格式:

ps[參數]

2.命(ming)令功能:

用來(lai)顯示(shi)當前進程的狀態

3.命令參(can)數:

a  顯示所有進程

-a 顯(xian)示同一(yi)終端下的所(suo)有程序

-A 顯示所有進程

c  顯示進(jin)程的真實名稱

-N 反向選擇

-e 等于“-A”

e  顯示環境(jing)變(bian)量

f  顯示(shi)程(cheng)序間的(de)關系

-H 顯示(shi)樹狀結構

r  顯示當前終端(duan)的進程(cheng)

T  顯示當前終端的所有程序

u  指定用(yong)戶的所有(you)進(jin)程

-au 顯示較詳細的資訊(xun)

-aux 顯示(shi)所有包含其他使用者(zhe)的行程 

-C<命(ming)令(ling)> 列出指定(ding)命(ming)令(ling)的(de)狀況

--lines<行數> 每(mei)頁顯示的行數

--width<字符數> 每頁(ye)顯示(shi)的字符數

--help 顯示幫助(zhu)信息

--version 顯(xian)示(shi)版本(ben)顯(xian)示(shi)

4.使用實例:

實例1:顯示所有進程信息

命(ming)令:

ps -A

輸出:

[root@localhost test6]# ps -A

  PID TTY          TIME CMD

    1 ?      &nbsp; 00:00:00 init

    2 ?        00:00:01 migration/0

    3 ?     &nbsp;  00:00:00 ksoftirqd/0

    4 ?  &nbsp;  &nbsp;  00:00:01 migration/1

    5 ?        00:00:00 ksoftirqd/1

    6 ?        00:29:57 events/0

   &nbsp;7 ?        00:00:00 events/1

    8&nbsp;?        00:00:00 khelper

   49 ?     &nbsp;  00:00:00 kthread

   54 ?   ;     00:00:00 kblockd/0

&nbsp;  55 ?        00:00:00 kblockd/1

   56 ?        00:00:00 kacpid

  217 ?     &nbsp;  00:00:00 cqueue/0

  ……省略部分結果

說明:

實(shi)例2:顯(xian)示指定(ding)用戶信息

命(ming)令:

ps -u root

輸出:

[root@localhost test6]# ps -u root

  PID TTY  &nbsp;       TIME CMD

    1 ?&nbsp;       00:00:00 init

    2 ?      ;  00:00:01 migration/0

  &nbsp; 3 ?        00:00:00 ksoftirqd/0

    4 ?        00:00:01&nbsp;migration/1

    5&nbsp;?        00:00:00 ksoftirqd/1

  ;  6 ?        00:29:57 events/0

&nbsp;  &nbsp;7 ?        00:00:00 events/1

    8 ?    &nbsp;   00:00:00 khelper

   49 ?&nbsp;       00:00:00 kthread

   54 ?   &nbsp;    00:00:00 kblockd/0

   55 ?        00:00:00 kblockd/1

  ; 56 ?        00:00:00 kacpid

    ……省略部分結(jie)果

說(shuo)明(ming):

實例3:顯(xian)示(shi)所有進程信(xin)息(xi),連同命令(ling)行

命令:

ps -ef

輸出:

[root@localhost test6]# ps -ef

UID        PID &nbsp;PPID  C STIME TTY          ;TIME CMD

root         1     0  0 Nov02 ?        00:00:00 init [3]    &nbsp;             

root    &nbsp;    2     1  0&nbsp;Nov02 ?      &nbsp; 00:00:01 [migration/0]

root &nbsp;       3     1  0 Nov02&nbsp;?        00:00:00 [ksoftirqd/0]

root         4     1  0 Nov02 ?   &nbsp;    00:00:01 [migration/1]

root         5     1  0 Nov02 ?        00:00:00&nbsp;[ksoftirqd/1]

root     ;    6     1  0 Nov02 ?        00:29:57 [events/0]

root  &nbsp;      7     1  ;0 Nov02 ?        00:00:00 [events/1]

root&nbsp;  &nbsp;     8     1  0 Nov02 ? &nbsp;      00:00:00 [khelper]

root     &nbsp;  49     1  0 Nov02 ?        00:00:00 [kthread]

root       &nbsp;54    49  0 Nov02 ?    &nbsp;   00:00:00 [kblockd/0]

root  &nbsp;   &nbsp; 55    49 &nbsp;0 Nov02 ?   &nbsp;    00:00:00 [kblockd/1]

root        56    49  0 Nov02&nbsp;?        00:00:00 [kacpid]

……省略部分結果(guo)

說明:

實例4: ps 與grep 常用(yong)組合用(yong)法(fa),查找特定進程

命令(ling):

ps -ef|grep ssh

輸出:

[root@localhost test6]# ps -ef|grep ssh

root      2720 ;    1  0 Nov02 ?        00:00:00 /usr/sbin/sshd

root     17394 &nbsp;2720  0 14:58 ?        00:00:00 sshd: root@pts/0 

root     17465 17398  0 15:57 pts/0    00:00:00&nbsp;grep ssh

說明:

實例5:將目前屬于您自己這次登入(ru)的 PID 與相關信息列示出(chu)來(lai)

命令(ling):

ps -l

輸出:

[root@localhost test6]# ps -l

F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD

4 S     0 ;17398 17394  0  75   0 - ;16543 wait   pts/0    00:00:00 bash

4 R     0 17469 17398  0  77   0 - 15877 -      pts/0 &nbsp;  00:00:00 ps

說(shuo)明(ming):

各相關信(xin)息的(de)意義:

F 代表這個程(cheng)序的旗標(biao) (flag), 4 代表使用(yong)者為 super user

S 代表這(zhe)個程序的(de)狀(zhuang)態 (STAT),關(guan)于各 STAT 的(de)意(yi)義將在內文介紹

UID 程序被該 UID 所擁有

PID 就是這個程(cheng)序的 ID !

PPID 則是其上級(ji)父程序的(de)ID

C CPU 使用的資源(yuan)百分比(bi)

PRI 這個是(shi) Priority (優先執(zhi)行(xing)序) 的縮寫(xie),詳細后面介紹

NI&nbsp;這個是 Nice 值,在下(xia)一(yi)小(xiao)節我們會持續介紹

ADDR 這個(ge)(ge)是 kernel function,指出該程序(xu)在內(nei)存的(de)(de)那個(ge)(ge)部分。如果是個(ge)(ge) running的(de)(de)程序(xu),一般(ban)就(jiu)是 "-"

SZ 使用掉(diao)的(de)內存大小

WCHAN 目前(qian)這個程序是否(fou)正在運(yun)作(zuo)當中(zhong),若為 - 表示正在運(yun)作(zuo)

TTY 登入(ru)者的終端機(ji)位置(zhi)

TIME 使用(yong)掉(diao)的 CPU 時間。

CMD 所下達(da)的指令為何(he)

在預設(she)的(de)情況下, ps 僅會列出與(yu)目前所在的(de) bash shell 有(you)關(guan)的(de) PID 而已(yi),所以, 當我使(shi)用 ps -l 的(de)時候,只(zhi)有(you)三個 PID

實(shi)例6:列出(chu)目前(qian)所有(you)的(de)正在(zai)內存(cun)當中的(de)程(cheng)序

命令:

ps aux

輸出(chu):

[root@localhost test6]# ps aux

USER     &nbsp; PID %CPU %MEM    VSZ   RSS TTY  &nbsp;   STAT START   TIME COMMAND

root &nbsp;       1  0.0  0.0  10368   676 ?        Ss   Nov02   0:00 init [3] &nbsp;                

root       &nbsp; 2  0.0  0.0      0     0 ?        S<   Nov02 ;  0:01 [migration/0]

root        &nbsp;3  0.0  0.0      0  &nbsp;  0 ?        SN&nbsp;  Nov02   0:00 [ksoftirqd/0]

root&nbsp;        4  0.0  0.0      0     0 ?        S< &nbsp; Nov02   0:01 [migration/1]

root   &nbsp;     5  0.0  0.0      0  ;   0 ?        SN   Nov02   0:00 [ksoftirqd/1]

root&nbsp;        6  0.0  0.0 &nbsp;    0     0 ?        S<   Nov02  29:57 [events/0]

root         7  0.0  0.0      0  ;   0 ?    &nbsp;   S<   Nov02   0:00 [events/1]

root&nbsp;        8  0.0&nbsp; 0.0      0     0 ?        S<   Nov02   0:00 [khelper]

root     &nbsp;&nbsp; 49  0.0  0.0      0     0 ?        S< ;  Nov02   0:00 [kthread]

root      ;  54  0.0  0.0    &nbsp; 0     0 ?        S<   Nov02   0:00 [kblockd/0]

root   &nbsp;    55  0.0 &nbsp;0.0      0     0 ?        S<   Nov02   0:00 [kblockd/1]

root  &nbsp;     56  0.0  0.0      0     0 ?        S<   Nov02   0:00 [kacpid]

……省(sheng)略(lve)部分結果(guo)

說明(ming):

USER:該 process 屬于那個使用者賬(zhang)號的

PID :該 process 的號碼

%CPU:該(gai) process 使(shi)用掉的&nbsp;CPU&nbsp;資源百分比

%MEM:該 process 所占用的物理內存(cun)百分(fen)比

VSZ :該 process ;使用掉(diao)的虛擬內存量(liang) (Kbytes)

RSS :該&nbsp;process 占用的固定的內存量(liang) (Kbytes)

TTY :該 process 是(shi)(shi)在那個終端(duan)機(ji)上(shang)面運(yun)作,若(ruo)與終端(duan)機(ji)無(wu)關,則(ze)顯示 ?,另(ling)外,&nbsp;tty1-tty6 是(shi)(shi)本機(ji)上(shang)面的(de)登入者程序(xu),若(ruo)為 pts/0 ;等(deng)等(deng)的(de),則(ze)表示為由(you)網絡連接進主機(ji)的(de)程序(xu)。

STAT:該程序目前的狀態,主要的狀態有(you)

R :該程序目前正在運作(zuo),或者是可被運作(zuo)

S :該程序(xu)目(mu)前正在睡(shui)眠當中 (可說是 idle 狀態),但(dan)可被某些訊號 (signal) 喚醒。

T :該程序目(mu)前正在偵測或者是停止了

Z :該程序(xu)應該已經終(zhong)止,但是其父程序(xu)卻無法正常的終(zhong)止他,造(zao)成(cheng) zombie ;(疆(jiang)尸) 程序(xu)的狀態

START:該 ;process 被觸發(fa)啟(qi)動的(de)時(shi)間

TIME :該 process 實(shi)際使(shi)用&nbsp;CPU 運作的時間

COMMAND:該程序(xu)的實際(ji)指令

實(shi)例7:列(lie)出類似程序(xu)樹的程序(xu)顯示(shi)

命令(ling):

ps -axjf

輸出:

[root@localhost test6]# ps -axjf

Warning: bad syntax, perhaps&nbsp;a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQ

 PPID   PID  PGID   SID TTY      TPGID STAT &nbsp; UID   TIME ;COMMAND

    0     1     1     1 ?           -1 Ss  ;     0   0:00 init [3]     &nbsp;        &nbsp;   

    1 &nbsp;   2     1     1 ?           -1&nbsp;S<       0   0:01 [migration/0]

    1     3     1 &nbsp; &nbsp; 1 ?           -1 SN       0   0:00 [ksoftirqd/0]

    1     4     1     1 ?        &nbsp;  -1 S<      &nbsp;0   0:01 [migration/1]

    1     5     1     1 ?           -1 SN       0   0:00 [ksoftirqd/1]

    1     6     1     1 ?           -1 S<       0  29:58 [events/0]

    1     7     1  &nbsp;  1 ?      &nbsp;    -1 S<       0   0:00 [events/1]

    1    &nbsp;8     1     1 ?           -1 S<       0   0:00 [khelper]

    1    49     1    &nbsp;1 ?           -1 S<       0   0:00 [kthread]

   49    54  &nbsp;  1    &nbsp;1 ?           -1 S<       0   0:00  \_ [kblockd/0]

   49    55    &nbsp;1     1 ? &nbsp;         -1 S<       0   0:00  \_ [kblockd/1]

   49&nbsp;   56     1     1 ?           -1 S<       0   0:00 ; \_ [kacpid]

說明:

實例8:找出(chu)與 cron 與 syslog 這(zhe)兩個服(fu)務有關的 PID 號碼

命(ming)令:

輸出:

[root@localhost test6]# ps aux | egrep '(cron|syslog)'

root      2682  0.0  0.0  83384  2000 ?        Sl &nbsp; Nov02   0:00 /sbin/rsyslogd -i /var/run/syslogd.pid -c 5

root      2735  0.0  0.0  74812  1140 ?&nbsp;  &nbsp;    Ss   Nov02   0:00 crond

root     17475  0.0  0.0  61180   832 pts/0    S+   16:27   0:00 egrep (cron|syslog)

[root@localhost test6]#

說明:

其他實例:

1.&nbsp;可以用 |&nbsp;管道和(he) more 連(lian)接起來分頁查看

命令:

ps -aux |more

2. 把所有進程顯示(shi)出來,并輸出到ps001.txt文件

命令:

ps -aux > ps001.txt

3. 輸出指定(ding)的(de)字段

命令:

 ps -o pid,ppid,pgrp,session,tpgid,comm

輸(shu)出(chu):

[root@localhost test6]# ps -o pid,ppid,pgrp,session,tpgid,comm

  PID  PPID  PGRP  SESS&nbsp;TPGID COMMAND

17398 17394 17398 17398 17478 ;bash

17478 17398 17478 17398&nbsp;17478 ps

[root@localhost test6]#

posted @ 2012-12-19 09:30  peida  閱讀(298245)  評論(14)    收藏  舉報