Live data from Hacker News

The Unix `Who` Command

gauthier.uk

31–40 of 43 posts

Re: The Unix `Who` Command

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

It runs multiple expressions. That is

  sed '/pattern1/d
  pattern2/d'
is the same with

  sed '/pattern1/d; /pattern2/d'
and

  sed -e '/pattern1/d' -e '/pattern2/d'
I believe those are portable across all `sed` implementations, and they at least work with GNU `sed --posix` and plan9port's sed.

Re: The Unix `Who` Command

#33

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.

Thanks for the help! It works!

Re: The Unix `Who` Command

#35
post #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`…

Thanks to setlogin()/getlogin() some operating systems are frustratingly close to the point where all of the relevant information can be read straight out of the kernel's process table, without need for coöperatively maintaining a data file.

On FreeBSD, for example, one can do everything except filter out the terminals where no-one is logged on yet and print a "FROM" column.

Re: The Unix `Who` Command

#36

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.

How useful is that book nowadays? Is it still worth purchasing?

Re: The Unix `Who` Command

#37
post #18

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.

Is /proc as portable as `ps`?

I guess that Linux `/proc` is different from Plan 9 `/proc`, and Linux `ps` is different from Plan 9 `ps`.

So maybe yes.

Re: The Unix `Who` Command

#38
post #18

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.

Is /proc as portable as `ps`?

There's a long explanation when it comes to ps, but the very short answer is twofold:

* Don't parse the output of ps, unless it is my ps command (or plan 9's one, as here). See https://unix.stackexchange.com/a/593198/5132 and https://unix.stackexchange.com/a/578816/5132 , and their further reading, especially Greg Wooledge's article.

* /proc is as portable as ps, but that doesn't really amount to much because neither is really portable at all. Pretty much every operating system's /proc is different; and no implementation of the ps command fully conforms to even the limited subset laid out in the Single Unix Specification.

Re: The Unix `Who` Command

#39

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.

How useful is that book nowadays? Is it still worth purchasing?

Yeah wondering if this would be interesting to do as a recreation project. Is copyright 2003 and mostly unvailable -- Amazon dares to "rent" it to me for 45$.... give me a break.

Re: The Unix `Who` Command

#40
post #25

who is 66 % waste: w is 300 % shorter and shows up to 721 % more valuable information.

who shows where the session is coming from which is useful for me where random people connect with the same system account. (OK w -f shows this)

There's something delightfully absurd about invoking who and getting told where they're logging in from. There's an Abbot and Costello skit in there waiting to come out.

This is why I love computing. It's putting abject insanity to good use.

Post reply on HN