For me, uptime
yields 9 users, but
ps -Af | cut -f1 -d' ' | sort | uniq | wc -l
yields 14.
I'm not exactly sure where the 9 is coming from.
Before I jump to conclusions though, please let me know if you guys do not have such a discrepancy.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityYou're comparing apples and oranges.
ps
will list the processes running. You're then getting the count of unique process-owning user ids.
uptime
will report the users logged on. By using utmp. More details at https://github.com/coreutils/coreutils/blob/master/src/uptime.c#L177
So, comparison of output, highlighting this, below.
# 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
#
w
to see more information about those 9 users. Yourps -Af
pipeline does not work at all on any of my systems, but have you looked at what it's reporting without usingwc -l
? It is probably showing some UIDs that don't show up inuptime
/w
likenoaccess
,nobody
, etcw
. Thank you. Yes, that is indeed what was happening. (On a side note, the -A means 'all', and -f means 'full'. Maybe try -e instead of -A? Idk what version of ps you are using, but mine is procps-ng ps(1)). A follow up: what is the difference between users that show up inw
, and users likenobody
, etc.?