Understanding UNIX/LINUX Programming: A Guide to Theory and Practice by Bruce Molay is a work which has the reader learn system programming by re-implementing UNIX commands.
who is the focus of Chapter 2.
I was confused - is "who mom hates" supposed to do something interesting?
On my Mac it seems any two arguments are allowed as an alias for "am i", so long as the first doesn't start with "-".
Looking it up, https://unix.stackexchange.com/questions/108145/is-who-mom-l... suggests it's a well-known in-joke.
FWIW, on my FreeBSD machine, only "who am i"/"who am I" are allowed.
I love your simple demonstration of strace reverse engineering a UNIX command. Probably a very silly question but I get this compile error? mywho.c:8:13: error: use of undeclared identifier 'LC_ALL' setlocale(LC_ALL, ""); I should solve it myself but since you are here?
I was hoping to see why who was better than w or similar, instead I was pleasently surprised to find someone taking a really simple unix command, reverse engineering it, and reimplementing it
The comment "initialize the utmp structure" is wrong. You have declared the struct here but it is uninitialized.
And there is no point in setting the locale, since your program never uses it.
I was legitimately confused for a second when I saw `Who` capitalized, but it must have been some automatic HN formatting - it's lower-case is the linked blog post.
who is 66 % waste: w is 300 % shorter and shows up to 721 % more valuable information.
Nice article. Reading the ‚who(1)‘ manpage would also have revealed ‚utmp‘ to be the relevant file, of course.
I’ve found grep to be unreliable or behave unexpectedly with strace. Even when piping to strings first, although not sure if that is of any consequence. Anyone know why that is or experienced the same?
His "who" implementation is 73 lines (21 if you remove blank lines and comments). Compare that to 836 in GNU Coreutils[0].
[0] https://github.com/coreutils/coreutils/blob/master/src/who.c
It's funny to me, because the way I came up in Unix, `utmp` was one of the first things you learned about: you were using Unix not because you installed it but because every system you might want to break into (for instance, to get to IRC through an outdial or a gateway) was running it, and they were all multi-user shell machines, and you wanted to make sure you weren't showing up in `who`. I probably knew the `utmp` format before I knew how to use `find`.
You'll find, in archives from hacking sites of the era, a whole variety of "utmp editors".