I'm looking for a simple way to determine the number of currently logged in users, using only the filesystem and basic bash functions (instead of using binaries).
The uptime binary appears to be reading from /var/run/utmp according the its source code, but /var/run/utmp doesn't seem to update in real time (it shows tty7 and pts/1-5 for my user, but I'm only on tty7 and pts/5 at the moment). However, the uptime binary correctly shows "2 users".
Note: Instead of relying on uptime or getutent() in C, I'm trying to better understand how the underlying system works.
What's the best place to find a current, accurate number of users logged into the system?
whowhich shows the current allocated terminals. – jofel Feb 7 at 9:34