“ps -o”和“ps o”之间的区别

时间:2015-04-07 06:02:39

标签: linux ps

在脚本中,我试图检索Linux上当前用户的所有进程的一些细节(RHEL 6.4和5.7)。我正在使用“ps -o pid,args,euser”。但我意识到它不包括同一用户拥有的进程,而是在不同的shell会话中启动。然后我尝试了“ps o pid,args,euser”,它有效。在手册页中,我看不出任何暗示这种差异的东西。是什么原因造成的?

$ ps  -o 'pid,args,euser'
  PID COMMAND                     EUSER
13491 -/usr/bin/ksh               ak
13519 bash                        ak
25427 ps -o pid,args,euser        ak

$ ps  o 'pid,args,euser'
  PID COMMAND                     EUSER
13491 -/usr/bin/ksh               ak
13519 bash                        ak
13699 -/usr/bin/ksh               ak
13727 bash                        ak
20573 -/usr/bin/ksh               ak
20616 bash                        ak
20996 -bash                       ak
21027 screen -D -R                ak
24842 /apps/ak/localdis/pub/cpyth ak
25460 ps o pid,args,euser         ak
25714 -/usr/bin/ksh               ak
25742 bash                        ak

2 个答案:

答案 0 :(得分:3)

引用手册页(通过Google上的第一个结果提供here

  ... The use of BSD-style options will also change the process
  selection to include processes on other terminals (TTYs) that are owned
  by you; alternately, this may be described as setting the selection to
  be the set of all processes filtered to exclude processes owned by
  other users or not on a terminal. These effects are not considered when
  options are described as being "identical" below, so -M will be
  considered identical to Z and so on.

答案 1 :(得分:1)

我不是百分百肯定,但可能是由于排序顺序和格式之间存在歧义。

可以找到详细信息here

  

O订单排序顺序。 (过载)

     

BSD O选项可以像-O(用户定义的输出格式,其中预定义了一些公共字段)或者可以用于指定排序顺序。启发式用于确定此选项的行为。要确保获得所需的行为(排序或格式化),请以其他方式指定选项(例如,使用-O或--sort)。

     

对于排序,过时的BSD O选项语法是O [+ | - ] k1 [,[+ | - ] k2 [,...]]。它根据由下面的OBSOLETE SORT KEYS部分中描述的单字母短键k1,k2,...序列指定的多级排序来命令进程列表。 “+”当前是可选的,只是重新迭代键上的默认方向,但可能有助于区分O类和O格式。 “ - ”仅在其前面的键上反转方向。