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

Re: multios and unnecessary processes



On Jan 10,  9:49am, Stephane Chazelas wrote:
} Subject: Re: multios and unnecessary processes
}
} > 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),

Ah, I should have thought of that.

} > 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
} 
} 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'
} 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'

If the number of processes spawned is important, you have to know when
to use curly braces and when to force a subshell with parens.  Curly
braces imply that the parent zsh sticks around and waits, whereas a
subshell with parens can simply do an exec.

zsh -fc '{ ( lsof -ag $$ -d 0-2,10-15 2>&1 >&3 3>&-; ) | tr a b 3>&-; } 3>&1'

COMMAND   PID  PGRP     USER   FD   TYPE DEVICE SIZE  NODE NAME
tr      26811 26811 schaefer    0r  FIFO    0,0      72995 pipe
tr      26811 26811 schaefer    1u   CHR  136,7          9 /dev/pts/7
tr      26811 26811 schaefer    2u   CHR  136,7          9 /dev/pts/7
lsof    26822 26811 schaefer    0u   CHR  136,7          9 /dev/pts/7
lsof    26822 26811 schaefer    1u   CHR  136,7          9 /dev/pts/7
lsof    26822 26811 schaefer    2w  FIFO    0,0      72995 pipe



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