Berkeley CSUA MOTD:Entry 39836
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/24 [General] UID:1000 Activity:popular
5/24    

2005/9/23-27 [Computer/SW/Languages/Perl] UID:39836 Activity:low
9/23    In the interests of not re-inventing the wheel: anyone know of
        a simple way,inside a  perl program ,to have a command start at
         the top of the minute? Thanks
        \_ cron
        \_ on a not-busy system cron is good at starting commands at the top
           of the minute but does not guarantee your job will run at that time,
           just at *some* time during the minute.  if you really actually need
           to run at the top of each minute, you could write a check vs the
           current time and do a "sleep 1" or something equally silly in a loop
           until $current_second_in_minute = 0 or whatever your criteria is.
           on a busy system all bets are off.
           \ This is a test program that needs to send specific data
             to a device which bins data  every sixty seconds and I am
             losing bits at the beginning and ending of the test
             because the test code does pay attention to where in the
             minute its started. Its a small but noticable error
             that I would like to get rid of; if possible.
             \_ What sort of granularity do you need? Less than a second?
                Less than two seconds? Less than a tenth of a second?
             \_ I would just sleep # of secs until next minute then run command
                if you need greater precision there are probably millisec calls
                \_ I would at least like to start off with a +/- 1
                   second and go from there. The sending and receiving
                   machines both use the same ntp servers so the clocks are  in
                   sync.
          \_ setitimer() is what you want, but it is in C, Time-HiRes uses
             it in perl. Or you could write a few lines of C to sent your
             perl a signal every min.
             \_ I'd second this. Let us know if there are other limitations.
        \_ use a real-time language (ie not perl/java)
           \_ What does the language have to do with it being real-time or
              not? There are plenty of real-time JVMs out there. The
              OS/environment is responsible for this, not the intrinsic
              language.