* zsh job control
@ 2002-02-25 18:55 frank
2002-02-25 19:41 ` Bart Schaefer
0 siblings, 1 reply; 3+ messages in thread
From: frank @ 2002-02-25 18:55 UTC (permalink / raw)
To: zsh-users
Hello
I have rtfm and vast portions of the man page and not found the answer to
this... This is not a bug but may well be a wishlist item if it doesn't
exist already
What I am looking for is an integration of the control forms like while,
for, etc with job control.
For instance, to start 4 jobs decompressing with gzip, I might do
ls **/*.gz | xargs -n 1 -P 4 gunzip
but this doesn't work well when the command is more complicated
ls **/*.gz | xargs -n 1 -P 4 -iFILE zsh -c "zcat FILE | fgrep foobar" >
results.txt
What I am hoping is that there is some sort of job control associated with
the standard zsh loops:
foreach[4] file (**/*.gz)
do
zcat $file | fgrep foobar
done > results.txt
or some such syntax. I recognize that I could simply background all the
processes but if I have hundreds of files, that creates hundreds of
processes- unworkable.
ideas?
---
frank@dicostanzo.com Suum Cuique
"Who needs friends when you can sit alone in your room and drink?"
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: zsh job control
2002-02-25 18:55 zsh job control frank
@ 2002-02-25 19:41 ` Bart Schaefer
2002-02-27 5:57 ` Geoff Wing
0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2002-02-25 19:41 UTC (permalink / raw)
To: frank; +Cc: zsh-users
On Mon, 25 Feb 2002 frank@espresso.hampshire.edu wrote:
> What I am looking for is an integration of the control forms like while,
> for, etc with job control.
There was a similar discussion a couple of years ago:
http://www.zsh.org/cgi-bin/mla/redirect?USERNUMBER=2676
(Hey, Geoff: When you use a redirect link like the one above, the
followups and references links at the bottom of the archive message
are broken.)
> What I am hoping is that there is some sort of job control associated with
> the standard zsh loops:
No, there's no magic syntax for this built in. You just have to make use
of the existing job control tools.
If you're not worried about always having exactly N jobs running, you can
do something simple like this:
N=4
pids=()
for file in **/*.gz
do
zcat $file | fgrep foobar &
pids=($pids $!)
if (( $#pids >= N )); then wait $pids[N]; pids=(); fi
done > results.txt
This starts four jobs and then waits for the fourth one to finish before
starting four more. You could use "wait" with no arguments to wait for
all four jobs to finish, but that would also wait for any other background
jobs that might have been started outside the loop.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2002-02-27 5:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-25 18:55 zsh job control frank
2002-02-25 19:41 ` Bart Schaefer
2002-02-27 5:57 ` Geoff Wing
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).