关于 ps -aux 的错误用法

转自 http://hi.baidu.com/drvial/item/b894e62c2286350e43634a68

 

 

很多人一直在使用ps -aux,其实这种用法是错误的,应该使用ps aux和ps -fe。man ps的第一页有一段话:
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

如果你在cygwin上运行ps -aux,那么你会得到下面的警告信息
ps: user x unknown

 

posted @ 2012-06-13 20:23  children  阅读(2631)  评论(0编辑  收藏  举报