From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13936 invoked by alias); 28 Dec 2013 20:43:37 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 18260 Received: (qmail 13024 invoked from network); 28 Dec 2013 20:43:31 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 From: Bart Schaefer Message-id: <131228124348.ZM27114@torch.brasslantern.com> Date: Sat, 28 Dec 2013 12:43:48 -0800 In-reply-to: <20131228164937.GA44192@cs2666372x.uwec.edu> Comments: In reply to Chris Johnson "The Halting Problem" (Dec 28, 10:49am) References: <20131228164937.GA44192@cs2666372x.uwec.edu> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: The Halting Problem MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Dec 28, 10:49am, Chris Johnson wrote: } } I tried backgrounding the long-running job, capturing its PID, and } passing that to sleepkill as the process to kill: } } java Foo & } longpid=$! } } sleepkill $longpid & } sleeppid=$! } } wait $longpid } # Kill the sleep timer, if necessary. } kill $sleeppid 2>/dev/null } } This kills the long-running job on timeout, but it also puts the job } in the background. Control-C won't kill it. You're almost there. If ctrl+c won't kill the java process in the above example, then there's some additional signal handling going on behind the scenes, and you just need to add a trap before the "wait": TRAPINT() { kill $longpid } So that when wait is interrupted you send off a signal to java. You probably also want to kill $sleeppid there, but because it's a shell function it may ignore the default TERM signal, so: TRAPINT() { kill $longpid kill -HUP -$$ } That should clean everything up.