Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Create a loop of 1000ms at the exact second

by gepebril69 (Scribe)
on Feb 20, 2015 at 10:16 UTC ( [id://1117308]=perlquestion: print w/replies, xml ) Need Help??

gepebril69 has asked for the wisdom of the Perl Monks concerning the following question:

Hi there

Create a loop every second at hh:mm:ss.000000

For netwerkmonitoring I want to create a loop of 1 second and do a ping to another server

The result of this ping, with timeout set to 10000msec I want to store in a logfile. This logfile (ping-test_yyyymmdd.log will so be filled with yyyy-mm-dd hh:mm:ss;<response in ms> entries

- To do a ping with timeout of 10000ms -> No problem
- Store in logfile -> No problem
- Change the logfile very day -> No problem
- Fork a child, as some pings can time out and you don't want to influence the next ping -> No problem

Create a loop every 1000ms at the exact second, that I don't understand. So after 12:00:00 localtime start an event (fork child) at
hh:mm:ss:ms
12:00:00.000
12:00:01.000
12:00:02.000
12:00:03.000
etc, etc

Any clue on how to handle that issue?

Thanks in advance

  • Comment on Create a loop of 1000ms at the exact second

Replies are listed 'Best First'.
Re: Create a loop of 1000ms at the exact second
by RichardK (Parson) on Feb 20, 2015 at 11:14 UTC

    That will depend on how you define 'exact', but on normal operating systems it's not possible to be all that precise.

    The help from Time::HiRes says this :-

    Remember that unless you are working on a hard realtime system, any cl +ocks and timers will be imprecise, especially so if you are working i +n a pre-emptive multiuser system. Understand the difference between w +allclock time and process time (in UNIX-like systems the sum of user +and system times). Any attempt to sleep for X seconds will most proba +bly end up sleeping more than that, but don't be surprised if you end + up sleeping slightly less.

      Thanks

      Created a test script and all statements are true, unfortunately

      Have found a suitable workaround

        Have found a suitable workaround.

        Which was what, exactly?

Re: Create a loop of 1000ms at the exact second
by Discipulus (Canon) on Feb 20, 2015 at 10:27 UTC
    Hello gepebril69,
    you can look at Time::Hires, if i understand your needs.
    Anyway 'exactly' is big word: i'll be satisfied by a good approximation.
    HtH
    L*
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
      Thanks for the help

        Hi

        If you really really want an exact timings, Try Raspberry PI with some RTOS, Like https://github.com/jameswalmsley/RaspberryPi-FreeRTOS.

        Thanks & Regards,
        Bakkiaraj M
        My Perl Gtk2 technology demo project - http://code.google.com/p/saaral-soft-search-spider/ , contributions are welcome.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1117308]
Front-paged by GotToBTru
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (1)
As of 2024-04-19 18:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found