Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: killing a program called with system() if it takes too long?

by xdg (Monsignor)
on Dec 18, 2008 at 18:19 UTC ( [id://731342] : note . print w/replies, xml ) Need Help??


in reply to killing a program called with system() if it takes too long?

...unless i manually kill (Ctrl+Alt+Del) ...

Are you on Windows? If so, run your external program with Win32::Job, which has timeout support built in.

use Win32::Job; my $job = Win32::Job->new; # Run 'perl Makefile.PL' for 10 seconds $job->spawn($Config{perlpath}, "perl Makefile.PL"); $job->run(10);

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.