Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

If I Want every child process to have EXACTLY 2 minutes to execute?

( #37205=categorized question: print w/ replies, xml ) Need Help??
Contributed by reyjrar on Oct 17, 2000 at 22:15 UTC
Q&A  > programs and processes


Description:

could I do something to kill off that child process regardless of where it is in its run after 2 minutes? I've heard messing with SIGs is bad and my first instinct is to:
SIG{'ALRM'} = sub {exit(0); } alarm '120';
but I don't want to break this box :)

thanks much..

Answer: If I Want every child process to have EXACTLY 2 minutes to execute?
contributed by tye

$SIG{ALRM}= sub { exit(0); }; alarm 120;

runrig is certainly right when programming in C (set a flag and return). However, Perl signal handlers are unsafe no matter what you do so I'd go with your solution (with the typos fixed as I've shown).

     - tye
Answer: If I Want every child process to have EXACTLY 2 minutes to execute?
contributed by runrig

Better to set a flag in the sig handler, and check for the flag throughout your code at key points. If you're paranoid anyway :)

Answer: If I Want every child process to have EXACTLY 2 minutes to execute?
contributed by AgentM

If your parent is just chillin' while the kiddies are out havin' fun, try using the signal killer in the parent, instead (it ain't got no nothin' betta ta doo!) Signals are still faulty in perl, but a process kill is a better process kill when you're not signaling yourself. sleep(120) in the parent while the kiddies are movin', after the wakeup, send a kill (or even better a sigqueue which no one uses!) to finish off those kiddies! Only one fatal signal involved which will best interrupt the kiddies at play- hurrah. If both the kiddie and the papa are executin', you can always write a short script to be their parents! (or pipe the PID to the "grandparent" and tell it to kill it after 2 minutes.) There's gotta be a UNIX command for that- if I could only remember...

Please (register and) log in if you wish to add an answer



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (7)
    As of 2014-11-22 14:46 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My preferred Perl binaries come from:














      Results (123 votes), past polls