<ps> ps aux 和ps -aux和 ps -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
参考:
http://walkerxk.blog.sohu.com/150633165.html
http://blog.chinaunix.net/uid-24701781-id-3343264.html

2. ps aux 和ps -ef
两者的输出结果差别不大,但展示风格不同。aux是BSD风格,-ef是System V风格。这是次要的区别,一个影响使用的区别是 aux会截断command列,而-ef不会。当结合grep时这种区别会影响到结果。
举例请参考: http://www.2cto.com/os/201303/197697.html

综上:以上三个命令推荐使用:ps –ef

猜你喜欢

转载自zoroeye.iteye.com/blog/2165233