From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14956 invoked from network); 1 Aug 2008 12:20:23 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00 autolearn=ham version=3.2.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 1 Aug 2008 12:20:23 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 50178 invoked from network); 1 Aug 2008 12:19:59 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 1 Aug 2008 12:19:59 -0000 Received: (qmail 22495 invoked by alias); 1 Aug 2008 12:18:47 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25365 Received: (qmail 22458 invoked from network); 1 Aug 2008 12:18:37 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 1 Aug 2008 12:18:38 -0000 Received: from smtp02.spamarrest.com (smtp02.spamarrest.com [67.228.25.94]) by bifrost.dotsrc.org (Postfix) with ESMTPS id 99454805A42F for ; Fri, 1 Aug 2008 14:18:31 +0200 (CEST) Received: from [192.168.1.2] (pool-71-100-213-6.tampfl.dsl-w.verizon.net [71.100.213.6]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp02.spamarrest.com (Postfix) with ESMTP id 31325FBC3FE for ; Fri, 1 Aug 2008 07:18:27 -0500 (CDT) Mime-Version: 1.0 Message-Id: Date: Fri, 1 Aug 2008 05:18:16 -0700 To: zsh-workers@sunsite.dk From: Dave Yost Subject: Problems with background jobs in a script. Content-Type: text/plain; charset="us-ascii" ; format="flowed" X-Virus-Scanned: ClamAV 0.92.1/7910/Fri Aug 1 13:14:31 2008 on bifrost X-Virus-Status: Clean 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 }