[Toybox] ps -t is cheating.

Isaac Dunham ibid.ag at gmail.com
Mon Oct 19 21:40:08 PDT 2015


On Mon, Oct 19, 2015 at 12:09:17AM -0500, Rob Landley wrote:
> So posix says this:
> 
> -t  termlist
>   Write information for processes associated with terminals given in
>   termlist. The application shall ensure that the termlist is a single
>   argument in the form of a <blank> or <comma>-separated list. Terminal
>   identifiers shall be given in an implementation-defined format. [XSI]
>   [Option Start]  On XSI-conformant systems, they shall be given in one
>   of two forms: the device's filename (for example, tty04) or, if the
>   device's filename starts with tty, just the identifier following the
>   characters tty (for example, "04" ). [Option End]
> 
> And once again posix is somewhere back before the 1980's because
> pseudo-terminals do not start with "/dev/tty". In the case of linux,
> they've been /dev/pts/12 since, apparently, 1998.

VTs start with /dev/tty, as do all interfaces that are theoretically
serial-based. Note that 'if'.

/dev/pts is actually the result of another part of POSIX (posix_openpt & co.)
 
> The ps man page says:
> 
>   -t ttylist
>        Select by tty.  This selects the processes associated with the
>        terminals given in ttylist.  Terminals (ttys, or screens for
>        text output) can be specified in several forms: /dev/ttyS1,
>        ttyS1, S1.  A plain "-" may be used to select processes not
>        attached to any terminal.
> 
> Which is, once again, outright lying, because "-t 41" matches pts/41 but
> -t 5 does _not_ match tty5. You have to say "-t tty5" to get the getty
> instance on there.
> 
> Meanwhile procutils "ps -t pts/41" works as does "ps -t pts/../tty5"
> which is just _creepy_ and I'm not doing that bit. And -tty S0 is of
> course /dev/ttyS0 not /dev/pts/S0.
> 
> I pine for a spec that means something,
> 
> Rob
> 
> P.S.  Once again, the hard part is writing help text so ps --help can
> explain the expected behavior succinctly. Yeah, I can do that, but how
> do I explain it in a way that makes it sound intentional: -t ## is a pts
> (unless maybe there isn't one? Does it fall back to tty5 if there's no
> pts5? Hard to test right now because I've got /dev/pts/68 but only
> /dev/tty63). Grrr. STOP TRYING TO BE CLEVER IN WAYS YOU DON'T EXPLAIN TO
> YOUR USERS IN THE MAN PAGE. Right special case "-t number" to be pts/
> instead of tty, accept pts/ to _not_ mean implicit tty prefix...

accept the following:
* filenames relative to /dev
* filenames relative to /dev/pts
* fallback to "/dev/tty<arg>".
No need to special case numbers.

This is *roughly* what procutils is doing, apart from that 'no need to
special-case numbers' I'd assume.

HTH,
Isaac

 1445316008.0


More information about the Toybox mailing list