Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: script suicide?

by bobn (Chaplain)
on Jul 21, 2003 at 01:09 UTC ( [id://276124]=note: print w/replies, xml ) Need Help??


in reply to script suicide?

perldoc -f alarm

Alarm allows a program to set a timer, at the expiration of which, a SIGALRM is sent to the program.

By eval'ing a block that includes re-assignment of the $SIG{ALRM} handler, then setting the alarm, the block can be made to exit if the timer expires before the block finishes normally. Examining $@ allows you to ensure that the block died for the expected reason. Very useful for anything that interacts over the network.

I think a process can only have one alarm running at a time, so if any of your routines or modules you're use'ing uses it already, you may be out of luck. But if the module is using alarm, it should be doing so to implment a timeout of it's own, so the trick is to make it timeout the way you want it to.

--Bob Niederman, http://bob-n.com

Replies are listed 'Best First'.
Re: Re: script suicide?
by diotalevi (Canon) on Jul 21, 2003 at 02:02 UTC

    Or you could assign a handler to $SIG{ALRM} and exit that way. I think that's the name anyway. Read perlipc for the details.

Re2: (Alarm::Concurrent) script suicide?
by bbfu (Curate) on Jul 21, 2003 at 03:17 UTC

    <plug> If you'd like to be able to have multiple alarms running, without affecting (or being affected by) other code you use which sets alarms, you could use the :OVERRIDE option of Alarm::Concurrent. One should be wary of using this option in production level code, as it overrides %SIG, but the OP's situation doesn't seem like it would be a problem. And, of course, this is just a standard warning, as I've never actually had it cause a problem for me.

    bbfu
    Black flowers blossom
    Fearless on my breath

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-25 13:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found