我正在尝试更深入地了解ps
Linux中的命令。
当我使用时我很困惑ps axjf
,ps -axjf
当我发现它们在手册中似乎有不同的含义但它们的输出几乎相同时。
它们之间的具体区别是什么?
对于这些选项,手册说:
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.
-a Select all processes except both session leaders (see getsid(2)) and processes not associated with a terminal.
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.
j BSD job control format.
-j Jobs format.
f ASCII art process hierarchy (forest).
-f Do full-format listing. This option can be combined with many other UNIX-style options to add additional columns. It also causes the command arguments to be printed. When used with -L, the NLWP (number of threads) and LWP (thread ID) columns will be added. See the c option, the format keyword args, and the format keyword comm.
尤其是f
and-f
选项,似乎-f
没有输出层次关系的意义。
我比较了这两个命令的输出,除了几行之外,它们几乎相同。
lightxy233@iZ8vb0rgcfh3yx60rzee1jZ:~$ ls
_axjf.txt axjf.txt
lightxy233@iZ8vb0rgcfh3yx60rzee1jZ:~$ diff _axjf.txt axjf.txt
81c81
< 2 639305 0 0 ? -1 I 0 0:00 \_ [kworker/u4:0-flush-252:0]
---
> 2 639305 0 0 ? -1 I 0 0:00 \_ [kworker/u4:0-events_unbound]
126,127c126,127
< 630827 630830 630830 630830 pts/0 641497 Ss 1000 0:00 | \_ -bash
< 630830 641497 641497 630830 pts/0 641497 R+ 1000 0:00 | | \_ ps axjf
---
> 630827 630830 630830 630830 pts/0 641448 Ss 1000 0:00 | \_ -bash
> 630830 641448 641448 630830 pts/0 641448 R+ 1000 0:00 | | \_ ps -axjf
129c129
< 630845 641496 630845 630845 ? -1 S 1000 0:00 | \_ sleep 1
---
> 630845 641447 630845 630845 ? -1 S 1000 0:00 | \_ sleep 1
我认为这可能涉及混合不同风格的 ps 命令,但我还没有找到很好的解释。