system() with timeout

Matt Lawrence matt.lawrence at virgin.net
Fri Apr 17 11:25:54 BST 2009


Nicholas Clark wrote:
> On Fri, Apr 17, 2009 at 09:24:01AM +0100, Matt Lawrence wrote:
>
>   
>> 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.
>>     
>
> Hmm, that's not good. Have you been able to nail it down sufficiently to make
> a bug report?
>   

I saw reference to it on the interweb, so assumed it was known about.

This is the closest thing I have to a proof:

#!/usr/bin/perl

while (1) {
    eval {
        local $SIG{USR1} = sub { die "USER 1!!" };
        kill USR1 => $$;
    };
}
__END__


When that's run in the background you'll see it grows fairly steadily 
and rapidly.


$ ./sig_test.pl &
[2] 15590
$ ps -Fp 15590
UID        PID  PPID  C    SZ   RSS PSR STIME TTY          TIME CMD
1001     15590  6142 99  6125 21432   1 10:50 pts/0    00:00:07 
/usr/bin/perl ./
$ ps -Fp 15590
UID        PID  PPID  C    SZ   RSS PSR STIME TTY          TIME CMD
1001     15590  6142 99  9260 33964   1 10:50 pts/0    00:00:11 
/usr/bin/perl ./


However, I just tried doing the same thing without the localised signal 
handler:

$SIG{USR1} = sub { die "USER 1!!" };
while (1) { eval { kill USR1 => $$ } }

and that's totally solid. I would assume that it's the handler 
subroutine not being cleaned up when we jump out of the eval.

I haven't had a chance to test any of this on the latest perl, 5.8.8 is 
the latest I've tried it with.

Matt



More information about the london.pm mailing list