zsh-workers
 help / color / mirror / code / Atom feed
* Problems with background jobs in a script.
@ 2008-08-01 12:18 Dave Yost
  2008-08-02 22:55 ` Bart Schaefer
  2008-08-03 11:27 ` Peter Stephenson
  0 siblings, 2 replies; 3+ messages in thread
From: Dave Yost @ 2008-08-01 12:18 UTC (permalink / raw)
  To: zsh-workers


The script below exhibits several problems.

All I'm trying to do is to get a script to recursively kill all of 
its background processes on exit. (In my case, this should be an 
issue only when the script is killed.)

My zsh version is 4.3.4

Thanks

Dave

  - - - - - - -

0 402 Z% /tmp/,x
[1]  - 38831 running    sleep 1000
[2]  + 38832 running    sleep 2000
/tmp/,x:kill:14: %3: no such job
The killed jobs still show up after the kills.
If we wait a bit, the jobs don't show up.
Now we start a sleep in the background with ()
Now we've killed it, but it's still running.
38837 s000  RN+    0:00.00 sleep 10
38839 s000  R+     0:00.00 grep sleep
0 403 Z%

  - - - - - - -

#!/bin/zsh

# Problems with background jobs in a script.

sleep 1000 &
sleep 2000 &

# This prints OK
jobs -l

# This prints nothing.
jobs -l | awk '{ print $3  $0 }'

kill %3
kill %2
kill %1

echo The killed jobs still show up after the kills.
jobs -l

echo "If we wait a bit, the jobs don't show up."
sleep 1
jobs -l

echo Now we start a sleep in the background with '()'

(
   sleep 10
   TRAPINT() {
     echo killing the sleep
     kill %%
   }
) &

kill %%
echo "Now we've killed it, but it's still running."
ps x | grep sleep

exit

# What I want to do is something like this:

TRAPEXIT() {
   kill $(
     jobs -l | awk '{ print $3 }'
   )
}

# or

TRAPEXIT() {
   while kill %% ; do ; done
}


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-08-03 11:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-01 12:18 Problems with background jobs in a script Dave Yost
2008-08-02 22:55 ` Bart Schaefer
2008-08-03 11:27 ` Peter Stephenson

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).