Geez. One can only hope that this "emergency message" doesn't mean something like "reactor coolant low"!

To make this into a single process, you will need to determine whether or not the socket for the device has a line for you to process in it or not. I think that you will need IO::Socket. This sort of thing would be done in what is called a "select server". Don't read from the socket unless you know that it has something to say.

I think this psuedo code would be fine in your application.

# open file handles for reading and reporting # set $since_report_secs (seconds) = 0 while (sleep (1)) { my $emergency = check_for_emergency(); if ($emergency) { do something; } report_awake_status(); } sub check_for_emergency { while (device port ready to read) { read line and check it for "emergency" return 1 if emergency; } return 0; # "no error"; } sub report_awake_status { $last_report_time++; if (more than 30 minutes) { send awake message, set counter back to zero } }
The above code essentially sets up a "polling loop". This is not as efficient as it "could be". But the logic for a simple single process is simple and I think that you will find that code like this doesn't take much CPU time.

In reply to Re^5: Timed event within a script by Marshall
in thread Timed event within a script by bajangerry

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.