ps的-aux选项代表什么?

Shi*_*ame 5 command-line syntax

您经常将选项传递给 CLI 命令,这会导致函数表现不同。它们都有一定的意义,例如

  • -v意思是“冗长”
  • -l意思是“列表”

ps命令列出了所有正在运行的进程,但如果您向其传递该 -aux选项,它将显示所有用户(包括 root)的进程。

所以我的问题是:命令-aux的参数ps代表什么?

Byt*_*der 7

来自man ps该命令的手册页ps(仅摘录):

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

因此,如果进程连接到终端,则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.
Run Code Online (Sandbox Code Playgroud)