From owner-freebsd-questions@FreeBSD.ORG Wed Jul 16 09:55:53 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 B8CA65C8 for ; Wed, 16 Jul 2014 09:55:53 +0000 (UTC) Received: from mail-yh0-x22d.google.com (mail-yh0-x22d.google.com [IPv6:2607:f8b0:4002:c01::22d]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 7E67724C6 for ; Wed, 16 Jul 2014 09:55:53 +0000 (UTC) Received: by mail-yh0-f45.google.com with SMTP id 29so321741yhl.18 for ; Wed, 16 Jul 2014 02:55:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=y+O2d4wi0JW08dfXsfLRSHfxp5MGsn5+ue2nOc0WVHk=; b=UlaLqpLdsY+GfzgC+yQZUscGfFToRsUo37LmMRqB54jGar6jppbxKIBoWlFje6+865 utotyf4uHrrfOEibTtSHDjSLG1u/cYyqHyh3377z8I4pKKla+2dXaz0JhVbWLmXHCdOM +8X9Bw4HjVDvE8jG7IPs1BJzB9oI6vl09mi/zTsG1Rb7M8f/k6lzmBFUaIKyb64bJeoC Tro/QPFQTqRDCylzqa8O2N7NZZ8n+y+EawP0aRC9ghmj8MQ9vFWgBgjvzAOhtdWkvSaM 2yB0f/dm6WD4seto/F25XMS0aVUOzGsM7GJnoXz8nwx2XF4269TdUCzQQT2K6NpWLVDf eRUw== MIME-Version: 1.0 X-Received: by 10.236.38.2 with SMTP id z2mr50388943yha.35.1405504552345; Wed, 16 Jul 2014 02:55:52 -0700 (PDT) Received: by 10.170.132.80 with HTTP; Wed, 16 Jul 2014 02:55:52 -0700 (PDT) In-Reply-To: <917611ACD1C0644B793C5B81@Mail-PC.tdx.co.uk> References: <917611ACD1C0644B793C5B81@Mail-PC.tdx.co.uk> Date: Wed, 16 Jul 2014 10:55:52 +0100 Message-ID: Subject: Re: sh 'sleep' and trap? From: krad To: Karl Pielorz Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.18 Cc: FreeBSD Questions 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:55:53 -0000 send a kill to the script and then to the sleep process itself? On 16 July 2014 10:31, Karl Pielorz wrote: > > 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 > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions- > unsubscribe@freebsd.org" >