Whoa. Careful there. Not only is this wasteful and platform-dependent, but it is also load dependent. If your computter is doing something else in another process, this loop might as well take three hours instead of the intended minute. In ComputerLand, it's good to be precise, so I would recommend
alarm(60); for an interruptable process. Don't even bother setting up a signal handler if unneeded. After 60 seconds, the script will crash and burn as intended.
If your thing cannot be interrupted, then keep track of the Time.
while($runningtime<$maxtime)
{
dosomething();
}
which is still polling (which is generally bad), but at least after you finish that iteration, you'll know whether to quit or not.
Another another option may be to use perlembed to embed an interpreter in a pthread, which is sent an internal signal to finish from another thread after 60 seconds of sleep. The murdered thread can have cleanup handlers installed to ensure that the important stuff got done and now you can finish. I would consider this the most professional way. Good luck!
AgentM Systems nor Nasca Enterprises nor
Bone::Easy nor Macperl is responsible for the
comments made by
AgentM. Remember, you can build any logical system with NOR.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.