语法注意: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.