Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 1 Feb 2005 13:20:15 -0800 (PST)
From:      Julian Elischer <julian@elischer.org>
To:        Peter Jeremy <PeterJeremy@optushome.com.au>
Cc:        current@freebsd.org
Subject:   Re: cynchronised sleep capbilty..
Message-ID:  <20050201130340.D92335@localhost>
In-Reply-To: <20050201190318.GE45608@cirb503493.alcatel.com.au>
References:  <20050201101113.J572@localhost> <20050201190318.GE45608@cirb503493.alcatel.com.au>

next in thread | previous in thread | raw e-mail | index | archive | help



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@elischer.org     +------>x   USA    \ a very strange
| (   OZ    )                                \___   ___ | country !
+- X_.---._/    presently in San Francisco       \_/   \\
          v



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050201130340.D92335>