`ps axjf`と`ps -axjf`の違い

`ps axjf`と`ps -axjf`の違い

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.

特にfandオプションは階層関係を出力するのに何の意味もないよう-fです。-f

2つのコマンドの出力を比較しましたが、数行を除いてほぼ同じです。

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コマンドを混在させることを含むと思いますが、まだ良い説明が見つかりませんでした。

ベストアンサー1

使用していると仮定procps-ngのpsps実際には、さまざまなスタイルを混在させ、オプションを解釈する方法が重要です。コマンドの重要な要素は、xオプションを使用することです。オプションはBSDスタイルでのみ存在し、コマンドで明示的であるため(-a引数がないため)、オプションセット全体はBSDスタイルとして解釈されます。その結果、同じオプションセットがアクティブになり、プロセスの違いによって出力の違いが発生しますaxjf-axjf

を削除すると、とのx違いを見ることができます。ps ajfps -ajf

xマニュアルページに表示されるあいまいさはpsオプションの使用に関連しています-u。 Unixスタイルとして解釈される場合、ユーザーを指定するには引数が必要です。したがって-ux(およびそのバリエーション、たとえば)はユーザーがいない-auxと解釈されます。この場合、procps-ngはBSDスタイルに切り替える経験的な方法を適用します。-u xxps

おすすめ記事