From owner-freebsd-current@FreeBSD.ORG Wed Feb 2 10:44:35 2005 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6BD2F16A4CF for ; Wed, 2 Feb 2005 10:44:35 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.196]) by mx1.FreeBSD.org (Postfix) with ESMTP id C370F43D39 for ; Wed, 2 Feb 2005 10:44:34 +0000 (GMT) (envelope-from peadar.edwards@gmail.com) Received: by wproxy.gmail.com with SMTP id 58so16647wri for ; Wed, 02 Feb 2005 02:44:31 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=AAEXdMycgavzk0oyfL/VseN3wDVW+/X7V8hKzu98H4k5NN5x4BvFSDt4B4/Ys9bMEQ3m/aeLdlwbAODeCC+lP4JPnLvza+pjsLkVW5DuHJt8nDB0gX1CPEvx3UjmbvShfpFGgR36oHF0iSqIZ93Zbius1+ltI0AWCHT/Dnc2uSg= Received: by 10.54.48.14 with SMTP id v14mr49116wrv; Wed, 02 Feb 2005 02:44:31 -0800 (PST) Received: by 10.54.57.20 with HTTP; Wed, 2 Feb 2005 02:44:31 -0800 (PST) Message-ID: <34cb7c8405020202446192b3bb@mail.gmail.com> Date: Wed, 2 Feb 2005 10:44:31 +0000 From: Peter Edwards To: Julian Elischer In-Reply-To: <20050201130340.D92335@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <20050201101113.J572@localhost> <20050201190318.GE45608@cirb503493.alcatel.com.au> <20050201130340.D92335@localhost> cc: Peter Jeremy cc: current@freebsd.org Subject: Re: cynchronised sleep capbilty.. X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Peter Edwards List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Feb 2005 10:44:35 -0000 On Tue, 1 Feb 2005 13:20:15 -0800 (PST), Julian Elischer wrote: > > > On Wed, 2 Feb 2005, Peter Jeremy wrote: > > > On Tue, 2005-Feb-01 10:20:24 -0800, Julian Elischer wrote: > > >while: > > >do > > > report results > > > sleep -until_next 10 > > >done > > > > How about: > > 1) Re-write the loop in C, perl or equivalent using setitimer(). You > > can system() out to collect the results. > > 2) Write a small C program that uses setitimer() and signals > > its parent whenever the timer triggers. Run it in the background > > and just pause within the sh loop. > > > > > > this is what I ended up doing.. > > # like sleep 10 except that it phase locks to teh 10 second boundary > # so that multiple machines are talking about the same sample period. I do something similar in C that requires no long-term drift, but it's a little more general: Use an absolute time for sleeps, rather than relative to "now". e.g.: time_t wakeup = time(0); while (!done) { // avoid multiple firings if "dostuff()" takes longer than interval while (wakeup < time(0)) wakeup += interval; sleepUntil(wakeup); dostuff(); } Where sleepUntil can be implemented either as a sleep relative to wakeupTime - now, or use a pthreads function like pthread_cond_timedwait(), for example. The shell code would probably be equally simple