語法注意:html
ps(process status)命令帶有2種不同的風格,分別是BSD和UNIX。新用戶常常會混淆和錯誤地解釋這兩種風格。因此要弄清楚他們,繼續操做以前這裏是一些基本的信息。linux
注意:"ps aux"和"ps -aux"不相同。例如"-u"用來顯示該用戶的進程。可是"u"則是顯示詳細的信息。express
BSD風格:在BSD風格的語法選項前不帶連字符。apache
UNIX/LINUX的風格:在linux風格的語法選項前面有一個破折號如常。…app
混合使用兩種Linux系統上的語法風格是好事兒。例如「ps ax -f」。但在這篇文章中,咱們將主要集中在UNIX風格的語法。less
如何使用ps命令呢?ssh
一、顯示全部進程:ide
下面的命令將列出全部的進程:工具
加上管道輸出給less,來滾動顯示post
"u"或者"-f"參數來顯示全部進程的詳細信息
注意:爲何用戶列不顯示個人用戶名,但顯示其餘用戶,如root、www等,對於全部的用戶名(包括你)若是長度大於8個字符,而後ps將只顯示UID,而不是用戶名。
三、經過名字和進程ID顯示進程:
經過名字或命令搜索進程,使用「-C」選項後面加搜索詞。
------------------------
要對進程進行監測和控制,首先必需要了解當前進程的狀況,也就是須要查看當前進程,而 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
ps 與grep 經常使用組合用法,查找特定進程
命令:
ps -ef|grep ssh
通常來講內存佔用大小有以下規律:VSS >= RSS >= PSS >= USS
The aim of this post is to provide information that will assist in interpreting memory reports from various tools so the true memory usage for Linux processes and the system can be determined.
Android has a tool called procrank (/system/xbin/procrank), which lists out the memory usage of Linux processes in order from highest to lowest usage. The sizes reported per process are VSS, RSS, PSS, and USS.
For the sake of simplicity in this description, memory will be expressed in terms of pages, rather than bytes. Linux systems like ours manage memory in 4096 byte pages at the lowest level.
VSS (reported as VSZ from ps) is the total accessible address space of a process.This size also includes memory that may not be resident in RAM like mallocs that have been allocated but not written to. VSS is of very little use for determing real memory usage of a process.
RSS is the total memory actually held in RAM for a process.RSS can be misleading, because it reports the total all of the shared libraries that the process uses, even though a shared library is only loaded into memory once regardless of how many processes use it. RSS is not an accurate representation of the memory usage for a single process.
PSS differs from RSS in that it reports the proportional size of its shared libraries, i.e. if three processes all use a shared library that has 30 pages, that library will only contribute 10 pages to the PSS that is reported for each of the three processes. PSS is a very useful number because when the PSS for all processes in the system are summed together, that is a good representation for the total memory usage in the system. When a process is killed, the shared libraries that contributed to its PSS will be proportionally distributed to the PSS totals for the remaining processes still using that library. In this way PSS can be slightly misleading, because when a process is killed, PSS does not accurately represent the memory returned to the overall system.
USS is the total private memory for a process, i.e. that memory that is completely unique to that process.USS is an extremely useful number because it indicates the true incremental cost of running a particular process. When a process is killed, the USS is the total memory that is actually returned to the system. USS is the best number to watch when initially suspicious of memory leaksin a process.
For systems that have Python available, there is also a nice tool calledsmem that will report memory statistics including all of these categories.