ps命令的-aux选项代表什么意思?

你经常在命令行中传递选项,以使函数的行为有所不同。它们都有各自的含义,例如:
- `-v` 表示 "详细模式" - `-l` 表示 "列表模式"
`ps` 命令用于列出所有正在运行的进程,但如果你传递 `-aux` 选项,它将显示所有用户的进程,

1尝试使用man ps命令,我相信a选项表示所有进程,x选项表示当前用户拥有的所有进程,而带有a选项和u选项则表示用户列表中所有用户的所有进程。 - George Udosen
1个回答

man psps命令的手册页(仅摘录):
   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.


   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.


   u      Display user-oriented format.

所以,如果进程与终端连接,a参数允许ps显示所有用户的进程,而不仅限于当前用户。 x使ps在列表中包括未连接到任何终端的进程。因此,ax一起使ps无限制地列出所有进程。 u只是改变输出格式和可见列。
正如@steeldriver在他的评论中正确提到的那样,ps有点特殊,因为它支持BSD风格(a)和GNU风格(-a)的两个参数。因此,尽管可能会实现相同的功能以便更容易迁移,但ps aux并不完全等同于ps -aux。手册的相关段落如下所示:
   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.

@steeldriver 你说得对,谢谢。我已经添加了。 - Byte Commander