Changeset 17284


Ignore:
Timestamp:
2008-09-15T12:26:54+12:00 (16 years ago)
Author:
ak19
Message:

The PerlDoc seems to indicate that it is necessary to call waitpid after launching a childprocess with open2(), in that otherwise we might be stuck with zombie child processes. In any case, this was necessary in a standalone wget script that used open2(), and the addition of new code to do this in Z3940Download.pm seems to make the code work as before.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/perllib/downloaders/Z3950Download.pm

    r17232 r17284  
    3636use BaseDownload;
    3737use IPC::Open2;
     38use POSIX ":sys_wait_h"; # for waitpid, http://perldoc.perl.org/functions/waitpid.html
    3839
    3940sub BEGIN {
     
    149150    my $childpid = open2(*YAZOUT, *YAZIN, $yaz)
    150151    or (print STDERR "<<Finished>>\n" and die "can't open pipe to yaz-client: $!");
     152    $self->{'pid'} = $childpid;
    151153    $self->{'YAZOUT'} = *YAZOUT;
    152154    $self->{'YAZIN'} = *YAZIN;
     
    187189
    188190    close($self->{'YAZOUT'});
     191
     192    # Is the following necessary? The PerlDoc on open2 (http://perldoc.perl.org/IPC/Open2.html)
     193    # says that waitpid must be called to "reap the child process", or otherwise it will hang
     194    # around like a zombie process in the background. Adding it here makes the code work as
     195    # before, but it is certainly necessary to call waitpid on wget (see WgetDownload.pm).
     196    # http://perldoc.perl.org/functions/waitpid.html
     197    my $kidpid;
     198    do {
     199    $kidpid = waitpid($self->{'pid'}, WNOHANG);
     200    } while $kidpid > 0; # waiting for pid to become -1
    189201}
    190202
Note: See TracChangeset for help on using the changeset viewer.