From owner-freebsd-current@FreeBSD.ORG Tue Feb 1 21:20:34 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 6AEB216A4CE for ; Tue, 1 Feb 2005 21:20:34 +0000 (GMT) Received: from pimout1-ext.prodigy.net (pimout1-ext.prodigy.net [207.115.63.77]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0883543D2D for ; Tue, 1 Feb 2005 21:20:34 +0000 (GMT) (envelope-from julian@elischer.org) Received: from [192.168.1.102] (adsl-216-100-134-143.dsl.snfc21.pacbell.net [216.100.134.143])j11LKGGS282548; Tue, 1 Feb 2005 16:20:21 -0500 Date: Tue, 1 Feb 2005 13:20:15 -0800 (PST) From: Julian Elischer X-X-Sender: julian@localhost To: Peter Jeremy In-Reply-To: <20050201190318.GE45608@cirb503493.alcatel.com.au> Message-ID: <20050201130340.D92335@localhost> References: <20050201101113.J572@localhost> <20050201190318.GE45608@cirb503493.alcatel.com.au> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: current@freebsd.org Subject: Re: cynchronised sleep capbilty.. X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Feb 2005 21:20:34 -0000 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. sync10 () { local SEC NEWSEC set `date +"%S"` SEC=$1 case $SEC in ?[012345678]) sleep $((9 - ($SEC % 10))) ;; ?9) ;; esac set `date +"%S"` NEWSEC=$1 while : do # check for overshoot of up to 7 seconds case $NEWSEC in ?[01234567]) return ;; esac sleep 0.1 set `date +"%S"` NEWSEC=$1 done } yeah, gross, but it works and there are tons of spare cycles on these machines :-) -- +------------------------------------+ ______ _ __ | __--_|\ Julian Elischer | \ U \/ / hard at work in | / \ julian@elischer.org +------>x USA \ a very strange | ( OZ ) \___ ___ | country ! +- X_.---._/ presently in San Francisco \_/ \\ v