Linux中ps aux、ps -aux、ps -ef之間的區別講解,-aux-ef

來源:互聯網
上載者:User

Linux中ps aux、ps -aux、ps -ef之間的區別講解,-aux-ef

Linux中的ps命令是Process Status的縮寫。ps命令用來列出系統中當前啟動並執行那些進程。ps命令列出的是當前那些進程的快照,就是執行ps命令的那個時刻的那些進程,如果想要動態顯示進程資訊,就可以使用top命令。

要對進程進行監測和控制,首先必須要瞭解當前進程的情況,也就是需要查看當前進程,而 ps 命令就是最基本同時也是非常強大的進程查看命令。使用該命令可以確定有哪些進程正在運行和啟動並執行狀態、進程是否結束、進程有沒有僵死、哪些進程佔用了過多的資源等等。總之大部分資訊都是可以通過執行該命令得到的。

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

kill 命令用於殺死進程。

linux上進程有5種狀態:

1. 運行(正在運行或在運行隊列中等待)

2. 中斷(休眠中, 受阻, 在等待某個條件的形成或接收到訊號)

3. 不可中斷(收到訊號不喚醒和不可運行, 進程必須等待直到有中斷髮生)

4. 僵死(進程已終止, 但進程描述符存在, 直到父進程調用wait4()系統調用後釋放)

5. 停止(進程收到SIGSTOP, SIGSTP, SIGTIN, SIGTOU訊號後停止運行)

ps工具標識進程的5種狀態代碼:

D 不可中斷 uninterruptible sleep (usually IO)

R 運行 runnable (on run queue)

S 中斷 sleeping

T 停止 traced or stopped

Z 僵死 a defunct (”zombie”) process

具體參數可以參考man ps或

http://www.cnblogs.com/peida/archive/2012/12/19/2824418.html

這裡重點討論的是ps aux和ps –aux的區別,及ps aux和ps –ef的區別。

1. ps aux和ps –aux

man ps 之後得到的結果:

ps displays information about a selection of the active processes. If you want a repetitive update of the selection and the displayed information, use top(1) instead.

Note that "ps -aux" is distinct from "ps aux". The POSIX and UNIX standards require that "ps -aux" print all processes owned by a user named "x", as well as printing all processes that would be selected by the -a option. If the user named "x" does not exist, this ps may interpret the command as "ps aux" instead and print a warning.

This behavior is intended to aid in transitioning old scripts and habits. It is fragile, subject to change, and thus should not be relied upon.

意思是:

請注意"ps -aux"不同於"ps aux"。POSIX和UNIX的標準要求"ps -aux"列印使用者名稱為"x"的使用者的所有進程,以及列印所有將由-a選項選擇的過程。如果使用者名稱為"x"不存在,ps的將會解釋為"ps aux",而且會列印一個警告。這種行為是為了協助轉換舊指令碼和習慣。它是脆弱的,即將更改,因此不應依賴。

如果你運行ps -aux >/dev/null,那麼你就會得到下面這行警告資訊

Warning: bad ps syntax, perhaps a bogus '-' See http://procps.sf.net/faq.html

綜上: 使用時兩者之間直接選擇ps aux

2. ps aux 和ps -ef

兩者的輸出結果差別不大,但展示風格不同。aux是BSD風格,-ef是System V風格。這是次要的區別,一個影響使用的區別是aux會截斷command列,而-ef不會。當結合grep時這種區別會影響到結果。

綜上:以上三個命令推薦使用:ps –ef

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.