Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: multios and unnecessary processes



On Sun, Jan 09, 2005 at 08:32:18PM +0000, Bart Schaefer wrote:
> On Jan 9,  4:47pm, Stephane Chazelas wrote:
> } Subject: multios and unnecessary processes
> }
> } zsh -c 'lsof -ag $$ -d0-2,10-15 >&2 >&- >&2'
> } 
> } and 
> } 
> } zsh -c 'lsof -ag $$ -d0-2,10-15 >&2'
> } 
> } To work the same.
> 
> Interesting.  For me, they *do* work the same *if* the command is run
> from the shell prompt rather than from "zsh -c".  In fact, I can only
> reproduce your results if I use a non-interactive shell.  If I put those
> two commands in files and execute the files with "zsh -if" I get (in
> both cases):
> 
> OMMAND   PID  PGRP     USER   FD   TYPE DEVICE SIZE   NODE NAME
> zsh     22683 22683 schaefer    0u   CHR  136,8          10 /dev/pts/8
> zsh     22683 22683 schaefer    1u   CHR  136,8          10 /dev/pts/8
> zsh     22683 22683 schaefer    2u   CHR  136,8          10 /dev/pts/8
> zsh     22683 22683 schaefer   10r   REG    3,1   36 159782 /tmp/lsof1
> zsh     22683 22683 schaefer   11u   CHR  136,8          10 /dev/pts/8
> 
> But if I leave off the -i I get the extra pipe descriptors in the first
> case.  I don't know offhand why multios would behave differently when
> the shell is interactive.
[...]

That's because of the -g option to lsof (process group $$, and
lsof is run in a different process group in interactive mode),
but you get the same behavior in interactive shells (you need to
give other options to lsof)

> } I came accross this while trying to make some code independant
> } of the multios setting (hence the >&- to cancel the teed
> } redirection).
> 
> I'm a little puzzled by that statement, because in your second example
> there is no teed redirection.  It's only the doubled >&2 that creates
> a teed redirection in the first place.
> 
> The right way to write multios-independent code is to wrap things in
> curly braces, e.g.:  { lsof -ag $$ -d0-2,10-15 >&2 } >&2

That was for:

{ cmd 2>&1 >&- >&3 3>&- | cmd2 3>&-; } 3>&-

(which can be written cmd 2> >(cmd2) on some systems)

Thanks for the

{ { cmd 2>&1 >&3 3>&-; } | cmd2 3>&-; } 3>&-

~$ zsh -c '{ { lsof -ag $$ -d 0-2,10-15 2>&1 >&3 3>&-; } | tr a b 3>&-; } 3>&1'
COMMAND  PID PGID     USER   FD   TYPE DEVICE SIZE  NODE NAME
tr      4506 4506 chazelas    0u  FIFO    0,7      10296 pipe
tr      4506 4506 chazelas    1u   CHR  136,1          3 /dev/pts/1
tr      4506 4506 chazelas    2u   CHR  136,1          3 /dev/pts/1
zsh     4507 4506 chazelas    0u   CHR  136,1          3 /dev/pts/1
zsh     4507 4506 chazelas    1w  FIFO    0,7      10296 pipe
zsh     4507 4506 chazelas    2u   CHR  136,1          3 /dev/pts/1
zsh     4507 4506 chazelas   10u   CHR  136,1          3 /dev/pts/1
zsh     4507 4506 chazelas   11r   CHR    1,3       2892 /dev/null
lsof    4508 4506 chazelas    0u   CHR  136,1          3 /dev/pts/1
lsof    4508 4506 chazelas    1u   CHR  136,1          3 /dev/pts/1
lsof    4508 4506 chazelas    2w  FIFO    0,7      10296 pipe

But that's still one more process compared to:

~$ zsh -o nomultios -c '{ lsof -ag $$ -d 0-2,10-15 2>&1 >&3 3>&- | tr a b 3>&-; } 3>&1'
COMMAND  PID PGID     USER   FD   TYPE DEVICE SIZE  NODE NAME
tr      4564 4564 chazelas    0u  FIFO    0,7      10603 pipe
tr      4564 4564 chazelas    1u   CHR  136,1          3 /dev/pts/1
tr      4564 4564 chazelas    2u   CHR  136,1          3 /dev/pts/1
lsof    4565 4564 chazelas    0u   CHR  136,1          3 /dev/pts/1
lsof    4565 4564 chazelas    1u   CHR  136,1          3 /dev/pts/1
lsof    4565 4564 chazelas    2w  FIFO    0,7      10603 pipe


-- 
Stéphane



Messages sorted by: Reverse Date, Date, Thread, Author