zsh-users
 help / color / mirror / code / Atom feed
* job control from script
@ 2005-12-11 17:21 rgo
  2005-12-11 19:58 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: rgo @ 2005-12-11 17:21 UTC (permalink / raw)
  To: zsh-users

Hi all. I wrote a little script, but I cannot to learn him to kill all his childs on SIGINT.
#script:
#!/bin/zsh
setopt MONITOR
function TRAPINT () {
    kill %
    return (( $1+128 ))
}
if [[ $1 == "start" ]]; then
    for (( i=0; i<$2; i++ )); do
        $0 dowork
    done
fi
# ... some long time stuff ...

#----end script

Why `kill %' doesn't work? And `kill %NUM'? And how can I fetch job list for use in script?


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

* Re: job control from script
  2005-12-11 17:21 job control from script rgo
@ 2005-12-11 19:58 ` Bart Schaefer
       [not found]   ` <20051211233432.59102a21.rgo@mail.interzet.ru>
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2005-12-11 19:58 UTC (permalink / raw)
  To: zsh-users

On Dec 11,  5:21pm, rgo wrote:
}
} Why `kill %' doesn't work?

What do you expect it to do, and why?

There's no job specifier that means "all jobs".  I've tried both bash and
ksh and "kill %" in those shells kills exactly one job (the most recent
one, as if "kill %+").  Zsh is the same.

} And `kill %NUM'? And how can I fetch job list for use in script?

You can either

	zmodload zsh/parameter
	kill %${(k)^jobstates}

or (if your version of zsh is recent enough that piping the jobs command
produces useful output) use

	jobs -p | while read jnum jpid text; do kill $jpid; done

The easiest thing, though, might be

	setopt MONITOR HUP
	function TRAPINT() { kill -HUP $$ }

which just says that on an INTerrupt, send a HUP signal, which will then
automatically be propagated to all the child processes.


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

* Re: job control from script
       [not found]   ` <20051211233432.59102a21.rgo@mail.interzet.ru>
@ 2005-12-12  1:07     ` Bart Schaefer
  0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2005-12-12  1:07 UTC (permalink / raw)
  To: zsh-users

On Dec 11, 11:34pm, rgo wrote:
}
} > 	jobs -p | while read jnum jpid text; do kill $jpid; done
} 
} zsh-4.2.5 [...] but pipe doesn't work.

Hmm, yes, there's definitely a bug.  Running "jobs" in a subshell of a non-
interactive shell hangs forever, almost as if "wait" had been executed,
even if MONITOR is set.

} > 	setopt MONITOR HUP
} > 	function TRAPINT() { kill -HUP $$ }
} 
} This is really work :). But gives a warning.

Change it to

	function TRAPINT() { exec 2>/dev/null; kill -HUP $$ }

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

end of thread, other threads:[~2005-12-12  1:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-11 17:21 job control from script rgo
2005-12-11 19:58 ` Bart Schaefer
     [not found]   ` <20051211233432.59102a21.rgo@mail.interzet.ru>
2005-12-12  1:07     ` Bart Schaefer

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