Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

timeout

Status
Not open for further replies.

justme77

Technical User
Feb 4, 2001
19
0
0
SG
Hi to all,
I have written a perl script to execute some command, like Tracert, and would like to improve it by including a time out function. This is in case Tracert hangs or something else happens. Any idea how I can go about doing it?

Thanks for the suggestions. cheers,
Just Me!!
 
Take a look at the alarm command. But, remember, it seems to only function well on a logical block (i.e. eval).

We use the following to do exactly what you are asking for in our internet home banking i/o logic:

eval {
local $SIG{ALRM} = sub {die "alarm\n" };
alarm(10);
local $/=undef;
.
.
.
alarm(0);
};

You can even make the argument sent to alarm a variable so the wait time can differ from function to function.

This seems to work well. Good luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top