zsh-users
 help / color / mirror / code / Atom feed
From: Simon Mages <mages.simon@googlemail.com>
To: zsh-users@zsh.org
Subject: job control in a script / zsh parallelism problem.
Date: Thu, 15 Mar 2012 12:25:18 +0100	[thread overview]
Message-ID: <CACxPiz3wYTeiyBggxTO7m_AOtav2psa_J2oXMMTU1Ax2CfxHJA@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1420 bytes --]

Hi,

i have some Problems with the job control in zsh.

In the following Script i tried to start 3 background processes, because
thats the only way i know to run things parallel in zsh, and write a "dot"
every two seconds during the runtime of this background Processes.

#!/usr/bin/zsh

#set -x

for i in a b c
do
 sleep 120 &
done

jobs -l

jobs -l |wc -l

var=`jobs -l|wc -l`

while [ $var -gt "0" ]
do
 print "."
 sleep 2
 var=`jobs -l|wc -l`
done

The Problem is that "jobs -l" in the Script writes an complete background
process list to stdout but "jobs -l|wc -l" just prints a "0"? When i run
"jobs -l|wc -l" manual with some background jobs it is working fine.

Can someone Point me i the right direction, i'm running out of useful ideas.

Here the Output of the Script without set -x:

#> ./test.sh
[2] 4916 running sleep 120
[3] - 1716 running sleep 120
[4] + 4160 running sleep 120
0

here with set -x:

#> ./test.sh
+./test.sh:5> i=a
+./test.sh:5> i=b
+./test.sh:7> sleep 120
+./test.sh:7> sleep 120
+./test.sh:5> i=c
+./test.sh:10> jobs -l
[2] 3532 running sleep 120
[3] - 1600 running sleep 120
[4] + 5292 running sleep 120
+./test.sh:7> sleep 120
+./test.sh:12> jobs -l
+./test.sh:12> wc -l
0
+./test.sh:14> var=+./test.sh:14> var=+./test.sh:14> jobs -l
+./test.sh:14> wc -l
+./test.sh:14> var=0
+./test.sh:16> [ 0 -gt 0 ']'


My test environment:

#> zsh --version
zsh 4.3.12 (i686-pc-cygwin)


BR Simon

             reply	other threads:[~2012-03-15 11:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-15 11:25 Simon Mages [this message]
2012-03-16 20:29 ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CACxPiz3wYTeiyBggxTO7m_AOtav2psa_J2oXMMTU1Ax2CfxHJA@mail.gmail.com \
    --to=mages.simon@googlemail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).