Re: cynchronised sleep capbilty..

From: Julian Elischer <julian_at_elischer.org>
Date: Tue, 1 Feb 2005 13:20:15 -0800 (PST)
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
Received on Tue Feb 01 2005 - 20:20:34 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:27 UTC