Shi*_*ame 5 command-line syntax
您经常将选项传递给 CLI 命令,这会导致函数表现不同。它们都有一定的意义,例如
-v
意思是“冗长”-l
意思是“列表”该ps
命令列出了所有正在运行的进程,但如果您向其传递该 -aux
选项,它将显示所有用户(包括 root)的进程。
所以我的问题是:命令-aux
的参数ps
代表什么?
来自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)