`ps aux`中的aux是什么意思?

How*_*ard 222 linux ps

ps aux似乎很方便地列出了所有进程及其状态和资源使用情况(Linux/BSD/MacOS),但是我无法理解aux使用man ps.

什么aux意思?

Joh*_*024 282

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

顺便说一句,man ps是一个很好的资源。

从历史上看,BSD 和 AT&T 开发了不兼容的ps. 没有前导破折号的选项(根据问题)是 BSD 风格,而有前导破折号的选项是 AT&T Unix 风格。最重要的是,Linux 开发了一个支持这两种样式的版本,然后添加了第三种样式,其中包含以双破折号开头的选项。

所有(或几乎所有)非嵌入式 Linux 发行版都使用procps套件的变体。上述选项在procpsps手册页中定义。

在评论中,您说您使用的是 Apple MacOS(我猜是 OSX)。对于OSX手册页ps在这里,它仅显示AT&T样式的支持。

  • 我不得不反对评论“`man ps` 是 mac OSX 上的一个很好的资源。手册页,只是在最后,指出 `ps aux` 是为了方便而维护的,但绝对没有暗示选项可以在结尾之前不带前导连字符的情况下指定,手册页很长而且非常复杂,读者在放弃和谷歌搜索这个 stackexchange 问题之前可能会花很多时间质疑他/她的理智。 (6认同)
  • `ps` 的 OSX 手册页确实在“旧版描述”部分下说“...... `ps aux` 仍然像在 Tiger 中那样工作”。 (3认同)
  • @HowardGuo 我已经更新了答案以反映 GNU (Linux) 版本的 `ps` 和 Apple OSX 版本之间的差异。这个问题目前被标记为“Linux”。如果您还询问 MacOS,您可能需要更新标签。 (2认同)

slm*_*slm 22

   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.
Run Code Online (Sandbox Code Playgroud)

例子

$ 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]
...
Run Code Online (Sandbox Code Playgroud)

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

开关aux将显示:

  • 所有用户的进程
  • 向您展示以面向用户的方式列出的流程(按用户名)
  • 向您展示所有进程,而不仅仅是连接到终端的进程。这将包括诸如 crond、upowerd 等服务之类的进程。


mwf*_*ley 10

理解手册的关键不是搜索“aux”(我首先尝试过),而是关注描述参数类型的部分ps

此版本的 ps 接受多种选项:

  1. UNIX 选项,可以分组并且必须以破折号开头。
  2. BSD 选项,可以分组并且不能与破折号一起使用。
  3. GNU 长选项,前面有两个破折号。

由此,我们知道这aux是一组(分组的)BSD 选项aux,这使它们更容易查找。

  • ax控制哪些进程被选择,并一起使用被明确描述以选择所有进程。

  • u 使用“面向用户”格式的输出,该格式提供更多列,包括用户 ID 和 CPU/内存使用情况。

因为u单独控制输出格式,您可以使用ps u $pid1 $pid2 ....