system() with timeout

Matt Lawrence matt.lawrence at virgin.net
Fri Apr 17 09:24:01 BST 2009


David Cantrell wrote:
> On Thu, Apr 16, 2009 at 07:44:39PM +0100, David Cantrell wrote:
>   
>> On Thu, Apr 16, 2009 at 06:32:08PM +0100, Paul LeoNerd Evans wrote:
>>     
>>> On Thu, Apr 16, 2009 at 06:18:45PM +0100, David Cantrell wrote:
>>>       
>>>> Anyone recommend a module to give me something like system(@list) but
>>>> with a timeout?
>>>>         
>>> Does IPC::Run have something suitable? I seem to recall it has quite a
>>> lot of interesting things to fiddle with...
>>>       
>> Yes, that looks like exactly what I wanted.  Thanks!
>>     
>
> But its documentation is utterly impenetrable, so I ended up doing ...
>
>     eval {
>         if(my $pid = fork()) { # parent
>             local $SIG{ALRM} = sub {
>                 kill 9, $pid; # quit RIGHT FUCKING NOW
>                 die("Child process timed out\n");
>             };
>             alarm(5);
>             waitpid($pid, 0);
>             alarm(0);
>         } else {
>             exec(@blah);
>         }
>     };
>
>   

I recently discovered that die() inside a signal handler causes a memory 
leak. I don't know if that would be a problem for you in this case.

I guess that might be related to the problem you were having before 
timing out system().

Matt



More information about the london.pm mailing list