ps aux似乎可以方便地列出所有进程及其状态和资源使用情况(Linux / BSD / MacOS),但是我无法使用aux来理解参数man ps的含义。

aux是什么意思?

评论

BTW ps =进程状态

#1 楼

a =显示所有用户的进程
u =显示进程的用户/所有者
x =还显示未连接到终端的进程

对,man ps是很好的资源。

从历史上看,BSD和AT&T开发了不兼容的ps版本。没有前划线的选项(根据问题)是BSD样式,而有前划线的选项是AT&T Unix样式。最重要的是,Linux开发了一个同时支持两种样式的版本,然后在其中添加了以双破折号开头的选项的第三种样式。 procps套件的变体。以上选项是在procps ps手册页中定义的。

在注释中,您说您正在使用Apple MacOS(我认为是OSX)。 ps的OSX手册页在这里,它仅显示对AT&T样式的支持。

评论


@HowardGuo您确定不是-u而是-u吗?

–jordanm
2013年12月28日下午5:26

@HowardGuo我已经更新了答案,以反映ps的GNU(Linux)版本与Apple OSX版本之间的区别。这个问题目前被标记为“ Linux”。如果您还询问MacOS,则可能要更新标签。

–John1024
2013年12月28日下午6:55

非常感谢。我刚刚检查了Linux中ps的手册页,其中包含有关aux的信息,MacOS的手册页中没有此类信息,这可能是文档错误。

–霍华德
13年12月28日在9:28

ps的OSX手册页确实在“旧版说明”部分下显示“ ... ps aux仍然像在Tiger中一样工作”。

– dev
15-10-24在15:23



我不得不反对这样的评论:“ man ps是mac OSX上的一个很好的资源。手册页仅在最后指出,保留ps aux是为了方便,但是绝对没有暗示可以指定选项手册页末尾没有引号,因此手册页又长又复杂,读者可以花很多时间询问他/她的理智,然后放弃并使用谷歌搜索这个stackexchange问​​题。

– Reb.Cabin
18年1月13日在23:31

#2 楼

   a      Lift the BSD-style "only yourself" restriction, which is imposed 
          upon the set of all processes when some BSD-style (without "-") 
          options are used or when the ps personality setting is BSD-like.  
          The set of processes selected in this manner is in addition to the 
          set of processes selected by other means.  An alternate 
          description is that this option causes ps to list all processes 
          with a terminal (tty), or to list all processes when used together 
          with the x option.

   u      Display user-oriented format.

   x      Lift the BSD-style "must have a tty" restriction, which is imposed 
          upon the set of all processes when some BSD-style (without "-") 
          options are used or when the ps personality setting is BSD-like.
          The set of processes selected in this manner is in addition to the 
          set of processes selected by other means.  An alternate 
          description is that this option causes ps to list all processes 
          owned by you (same EUID as ps), or to list all processes when used 
          together with the a option.


示例

$ ps aux | head -10
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0  51120  2796 ?        Ss   Dec22   0:09 /usr/lib/systemd/systemd --system --deserialize 22
root         2  0.0  0.0      0     0 ?        S    Dec22   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    Dec22   0:04 [ksoftirqd/0]
root         5  0.0  0.0      0     0 ?        S<   Dec22   0:00 [kworker/0:0H]
root         7  0.0  0.0      0     0 ?        S    Dec22   0:15 [migration/0]
root         8  0.0  0.0      0     0 ?        S    Dec22   0:00 [rcu_bh]
root         9  0.0  0.0      0     0 ?        S    Dec22   2:47 [rcu_sched]
...
saml      3015  0.0  0.0 117756   596 pts/2    Ss   Dec22   0:00 bash
saml      3093  0.9  4.1 1539436 330796 ?      Sl   Dec22  70:16 /usr/lib64/thunderbird/thunderbird
saml      3873  0.0  0.1 1482432 8628 ?        Sl   Dec22   0:02 gvim -f
root      5675  0.0  0.0 124096   412 ?        Ss   Dec22   0:02 /usr/sbin/crond -n
root      5777  0.0  0.0  51132  1068 ?        Ss   Dec22   0:08 /usr/sbin/wpa_supplicant -u -f /var/log/wpa_supplica
saml      5987  0.7  1.5 1237740 119876 ?      Sl   Dec26  14:05 /opt/google/chrome/chrome --type=renderer --lang=en-
root      6115  0.0  0.0      0     0 ?        S    Dec27   0:06 [kworker/0:2]
...


使用上述开关,您将获得有关上述过程的输出。

aux开关将向您显示:


所有用户的过程
向您显示以面向用户的方式列出的过程(按用户名) )
向您显示所有过程,而不仅仅是终端上附加的过程。这将包括诸如crond,upowered等服务之类的进程。


#3 楼

理解联机帮助页的关键不是搜索“ aux”(我首先尝试过),而是专注于描述ps所采用的参数种类的部分:的ps接受几种选项:


UNIX选项,可以分组,并且必须以破折号开头。
GNU long选项,前面带有两个破折号。 BSD选项auxau,这使它们看起来更容易查找。
x使用“面向用户”的格式输出,该列提供更多列,包括用户ID和CPU /内存使用情况。

由于仅a控制输出格式,因此您可以n使用x获得“ ps aux”样式的输出,仅用于特定过程。