「稼働時間」の「ユーザー」フィールドはどのように計算されますか?

「稼働時間」の「ユーザー」フィールドはどのように計算されますか?

私の場合、uptime9人のユーザーが作成されましたが、

ps -Af | cut -f1 -d' ' | sort | uniq | wc -l収量 14.

9がどこから出たのかよく分からない。

早急に結論を出す前に、そのような違いがないことを教えてください。

ベストアンサー1

あなたはリンゴとオレンジを比較しています。

ps実行中のプロセスが一覧表示されます。これにより、一意のプロセスを持つユーザーIDの数を取得できます。

uptimeログインしたユーザーが報告されます。詳しくはutmpをご覧ください。https://github.com/coreutils/coreutils/blob/master/src/uptime.c#L177

したがって、以下では出力比較に焦点を当てます。

# uptime
 16:52:37 up 30 days, 23:32,  1 user,  load average: 0.04, 0.04, 0.05
# w
 16:57:33 up 30 days, 23:37,  1 user,  load average: 0.00, 0.01, 0.05
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
steve    pts/0    cpc79909-stkp12- 16:50    5.00s  0.07s  0.28s sshd: steve [priv]
#


# ps -Af | cut -f1 -d' ' | sort | uniq | wc -l
7
# ps -Af | cut -f1 -d' ' | sort | uniq
chrony
dbus
polkitd
postfix
root
steve
UID
#

おすすめ記事