ps 的 -aux 选项代表什么?

ps 的 -aux 选项代表什么?

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

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

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

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

答案1

来自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.

因此,如果进程连接到终端,该a参数可以ps显示所有用户的进程,而不仅仅是当前用户的进程。

makes还包括列表中未连接到任何终端的进程。因此,xtogether会无限制地列出所有进程。psaxps

只是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.

相关内容