如果执行ps x
(观察有不 -
)则输出如下:
PID TTY STAT TIME COMMAND
2489 ? Ss 0:00 /lib/systemd/systemd --user
2490 ? S 0:00 (sd-pam)
2517 tty1 S+ 0:00 -bash
3830 tty4 S 0:00 -bash
4085 ? S 0:00 sshd: manueljordan@pts/0
4086 pts/0 Ss 0:00 -bash
4184 ? S 0:00 sshd: manueljordan@pts/1
4185 pts/1 Ss 0:00 -bash
4265 ? S 0:00 sshd: manueljordan@pts/2
4266 pts/2 Ss 0:00 -bash
4385 tty4 S+ 0:00 man ps
4395 tty4 S+ 0:00 pager
4805 pts/1 S+ 0:00 man ps
4815 pts/1 S+ 0:00 pager
4827 pts/0 S+ 0:00 less
4829 pts/2 R+ 0:00 ps x
到这里为止一切都很好并且是预期的。
刚刚播放就执行了ps -x
(观察有-
)然后输出如下:
PID TTY STAT TIME COMMAND
2489 ? Ss 0:00 /lib/systemd/systemd --user
2490 ? S 0:00 (sd-pam)
2517 tty1 S+ 0:00 -bash
3830 tty4 S 0:00 -bash
4085 ? S 0:00 sshd: manueljordan@pts/0
4086 pts/0 Ss 0:00 -bash
4184 ? S 0:00 sshd: manueljordan@pts/1
4185 pts/1 Ss 0:00 -bash
4265 ? R 0:00 sshd: manueljordan@pts/2
4266 pts/2 Ss 0:00 -bash
4385 tty4 S+ 0:00 man ps
4395 tty4 S+ 0:00 pager
4805 pts/1 S+ 0:00 man ps
4815 pts/1 S+ 0:00 pager
4827 pts/0 S+ 0:00 less
4830 pts/2 R+ 0:00 ps -x
实际上,除了代表执行命令的最新行之外,两者都是相等的
问题
-x
命令上下文中的含义是什么ps
?
是的,我已经阅读了这两篇文章man ps
,并且选项/参数ps --help all
的文档x
分别如下:
# Approach 1
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.
# Approach 2
x processes without controlling ttys
但似乎-x
并没有什么。老实说,当ps
命令执行时-x
- 理论上我预计会出现错误,因为-x
不存在,因为-x
没有记录。
额外问题
- 如果
-x
理论上不存在,因为没有记录,为什么没有抛出错误?
笔记我认为这可能是此命令的一种默认行为,但并非总是如此,例如它不适用于d
- 例如
ps -d
作品ps d
做不是工作 - 出现错误。
前者有记录,后者没有记录。所以错误是预料之中的