cynchronised sleep capbilty..
Julian Elischer
julian at elischer.org
Tue Feb 1 13:20:34 PST 2005
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) <kludge>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.</kludge>
>
>
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 at elischer.org +------>x USA \ a very strange
| ( OZ ) \___ ___ | country !
+- X_.---._/ presently in San Francisco \_/ \\
v
More information about the freebsd-current
mailing list