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

Re: Problems with background jobs in a script.



On Fri, 1 Aug 2008 05:18:16 -0700
Dave Yost <Dave@xxxxxxxx> wrote:
> 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.)

I'm actually suprised it gets as far as it does.  Essentially no thought
has been put into to job control for non-interactive shells (when the
MONITOR option is not set); it so happens zsh still uses its job table
for storing information about jobs it's started, but many of the fixes
to make things appear seamless (or at least more closely stitched) only
work with MONITOR.  That may be fixable to some extent (particularly
with background jobs where the task is already separate from the main
shell even without the normal job control OS support) but there's so
much to do to the shell I shouldn't hold your breath.

You could try pretending the script is interactive (with the -i option
--- I tried this it and certainly made a better stab at your script) but
that may have side effects.
 
Possibly it's simpler to keep track of the process numbers you need to
kill by recording them from $!.  However, since in this case the shell
doesn't guarantee to tell you when the process is terminated you can't
be absolutely sure you're killing the right process.

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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