How to list the current active login sessions?

Hi all,

I'm trying to list all the users that are currently logged in to the system, and information about their login session (tty or ssh, etc.). Basically something similar to what loginctl would show on a Linux machine.

How can I achieve this in FreeBSD?

Thanks!
 
The w command is ancient, and the historically accepted way to do this. To a large extent that's because it looks at the utmp file (which on FreeBSD is not actually called utmp), and therefore can get a pretty much ACID-correct look at the list of logged in users.

On modern Linux (last two years or so), loginctl has the same functionality, and for the same reason: on a systemd equipped machine, all logins go through systemd, so loginctl (part of the systemd utilities) can see a live status of who is logged in. I think on a systemd based Linux, the implementation of w ends up being a wrapper around loginctl. Why does loginctl even exists? Answering that would require a long rant about Lennart, and how he confuses his personal debugging tools with useful utilities, and how he wouldn't know what "requirements" are if someone shoved them up his ..., and how he disdains but imitates long standing traditions, so let's not go there.

Yes, but ... interpreting the output of ps requires knowledge, while w gives you the important part of the answers all pre-cooked. The two tools are overlapping yet orthogonal.
 
The w command is ancient, and the historically accepted way to do this. To a large extent that's because it looks at the utmp file (which on FreeBSD is not actually called utmp), and therefore can get a pretty much ACID-correct look at the list of logged in users.
Thanks for the insights! One question: What is "ACID-correct"?
 
Thanks for all the replies. After reading through the man pages for w and who, I'm starting to wonder what being "logged in" really means from the operating system's perspective. I mean, the user ntpd isn't considered to be "logged in" even if there is a ntpd process running, but a regular user is considered to be "logged in" when they are running some commands in a shell.

Is it the type of program being run that decides whether it is considered to be a "login session", or is it something else?
 
Thanks for all the replies. After reading through the man pages for w and who, I'm starting to wonder what being "logged in" really means from the operating system's perspective. I mean, the user ntpd isn't considered to be "logged in" even if there is a ntpd process running, but a regular user is considered to be "logged in" when they are running some commands in a shell.

Is it the type of program being run that decides whether it is considered to be a "login session", or is it something else?
Login usually means somebody is logging in through terminal.

See also last and lastlogin
Man last(1), lastlogin(8)
 
Back
Top