From owner-freebsd-questions@FreeBSD.ORG Wed Jul 16 09:36:22 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9C4171AD for ; Wed, 16 Jul 2014 09:36:22 +0000 (UTC) Received: from mail.tdx.com (mail.tdx.com [62.13.128.18]) by mx1.freebsd.org (Postfix) with ESMTP id 2CC2C2329 for ; Wed, 16 Jul 2014 09:36:21 +0000 (UTC) Received: from Mail-PC.tdx.co.uk (storm.tdx.co.uk [62.13.130.251]) (authenticated bits=0) by mail.tdx.com (8.14.3/8.14.3/) with ESMTP id s6G9VMkL009170 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 16 Jul 2014 10:31:22 +0100 (BST) Date: Wed, 16 Jul 2014 10:31:22 +0100 From: Karl Pielorz To: freebsd-questions@freebsd.org Subject: sh 'sleep' and trap? Message-ID: <917611ACD1C0644B793C5B81@Mail-PC.tdx.co.uk> X-Mailer: Mulberry/4.0.8 (Win32) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Jul 2014 09:36:22 -0000 Hi All, I have a script, similar to this: " #!/bin/sh echo $$ >/var/run/mypid.pid trap "rm /var/run/mypid.pid; exit 0" EXIT while [ 1 ] do do_stuff sleep 60 done " This works - but an attempt to 'kill' it, e.g. kill `head -1 /var/run/mypid.pid` Takes up to 60 seconds, before 'sleep' completes, control returns back to the shell - which see's the signal, and quits. Is there a better way of doing this? - i.e. some way the shell can 'pass time' but still receive signals in a timely manner? The only work around I could come up with was to change the 'sleep 60' into a loop that does 60 * 1 second sleeps, not ideal though :( Cheers, -Karl