Live data from Hacker News

The Unix `Who` Command

gauthier.uk

11–20 of 43 posts

Re: The Unix `Who` Command

#11
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?

Re: The Unix `Who` Command

#12
post #8

Earlier quoted context omitted.

> Of course, this only mocks the most basic features of the who command and doesn’t handle any option, like the famous `who am i` or `who mom hates`. it's not quite an apples to apples comparison as his rewrite doesn't handle any options or cleverness, but it's still a massive jump in LOC.

Nor is it anywhere near as portability. Though that's not a big issue these days.

If you don't care about all the features then Busybox's implementation will work fine at 170 lines inclusive of comments.

Re: The Unix `Who` Command

#13
post #3

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.

Any two non-option arguments returns the user of the invoking tty. "who is awesome" or "who foo bar" achieves the same result.

Re: The Unix `Who` Command

#14

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

plan 9 who is a 3 line shell script that just greps the output of ps and sorts it. You could eliminate ps and just grep through /proc but why reinvent the wheel when an existing tool already does part of the job?

I see some comments here citing a lack of options, most of which appear to have nothing to do with who is logged into the machine.

Re: The Unix `Who` Command

#15
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.

Re: The Unix `Who` Command

#16

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

V7 `who` was 62 lines; by V10 it was bloated up to 93.

Re: The Unix `Who` Command

#17
post #3

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 was confused because when I'm in tmux `who am i` (or `who mom hates` or `who -m`) prints nothing. I thought that might've been the joke -- I'm nobody (or something). When I detach from tmux and run it in the login shell directly it works as expected. The phrasing in the man page ("'am i' or 'mom likes' are usual.") is also pretty strange.

Re: The Unix `Who` Command

#18

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

plan 9 who is a 3 line shell script that just greps the output of ps and sorts it. You could eliminate ps and just grep through /proc but why reinvent the wheel when an existing tool already does part of the job? I see some comments here citing a lack of options, most of which appear to have nothing to do with who is logged into the machine.

Is /proc as portable as `ps`?

Re: The Unix `Who` Command

#19

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

plan 9 who is a 3 line shell script that just greps the output of ps and sorts it. You could eliminate ps and just grep through /proc but why reinvent the wheel when an existing tool already does part of the job? I see some comments here citing a lack of options, most of which appear to have nothing to do with who is logged into the machine.

[deleted]

Re: The Unix `Who` Command

#20

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?

Not the author as I had the same issue, add `#include ` after the other headers.
Post reply on HN