Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by reyjrar (Hermit)
on Oct 17, 2000 at 22:15 UTC ( #37205=perlquestion: print w/replies, xml ) Need Help??

reyjrar has asked for the wisdom of the Perl Monks concerning the following question: (programs and processes)

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..

Originally posted as a Categorized Question.

  • Comment on If I Want every child process to have EXACTLY 2 minutes to execute?
  • Download Code

Replies are listed 'Best First'.
Re: If I Want every child process to have EXACTLY 2 minutes to execute?
by tye (Sage) on Oct 17, 2000 at 22:28 UTC
    $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
Re: If I Want every child process to have EXACTLY 2 minutes to execute?
by runrig (Abbot) on Oct 17, 2000 at 22:21 UTC
    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 :)
Re: If I Want every child process to have EXACTLY 2 minutes to execute?
by AgentM (Curate) on Oct 17, 2000 at 23:13 UTC
    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...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://37205]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2021-04-18 20:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?