Live data from Hacker News

The Unix `Who` Command

gauthier.uk

21–30 of 43 posts

Re: The Unix `Who` Command

#21

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.

Source for the mentioned script: https://github.com/0intro/plan9/blob/master/rc/bin/who. Also, other utilities implemented as scripts are fshalt (P9's shutdown), kill, lookman (P9's apropos), uptime and whois.

Re: The Unix `Who` Command

#23

Earlier quoted context omitted.

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.

Source for the mentioned script: https://github.com/0intro/plan9/blob/master/rc/bin/who . Also, other utilities implemented as scripts are fshalt (P9's shutdown), kill, lookman (P9's apropos), uptime and whois.

Does anybody know why there are line breaks in the sed command?

Re: The Unix `Who` Command

#24
post #23

Earlier quoted context omitted.

Source for the mentioned script: https://github.com/0intro/plan9/blob/master/rc/bin/who . Also, other utilities implemented as scripts are fshalt (P9's shutdown), kill, lookman (P9's apropos), uptime and whois.

Does anybody know why there are line breaks in the sed command?

[deleted]

Re: The Unix `Who` Command

#26

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

You'll like this Rob Pike thread https://twitter.com/rob_pike/status/966896123548872705

Re: The Unix `Who` Command

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

Re: The Unix `Who` Command

#28
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".

Re: The Unix `Who` Command

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

Re: The Unix `Who` Command

#30

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?

You know it outputs to stderr, right? Also if you give it the option "-o -" it doesn't do what you might expect. Other than that I grep the output of strace all the time and it works for me.
Post reply on HN