wagnerc has asked for the wisdom of the Perl Monks concerning the following question:
So the rub is something to do with the $len == 0 condition. A sysread of 0 is supposed to indicate that the handle is at EOF. Can someone elucidate the handle destruction process in Perl? After this sub call every variable goes out of scope. Thanks.local $/ = undef; for ($i=0;$i<=$#hosts;$i++) { $pings[$i][0] = $hosts[$i]; my $pid; $pid = open $pings[$i][1], "-|", "$pingcmd $hosts[$i] $pingsize $p +ingnumber" or die "Error executing $pingcmd: $!\n";; my $old_flags = fcntl($pings[$i][1], F_GETFL, 0) or die "can't get flags: $!"; fcntl($pings[$i][1], F_SETFL, $old_flags | O_NONBLOCK) or die "can't set non blocking: $!"; $pings[$i][2] = $pid; print "$pingcmd, $hosts[$i], $pingsize, $pingnumber failure\n" unl +ess $pid; } READ: while (@pings) { for ($i=$#pings;$i>=0;$i--) { my $buf; my $len = sysread $pings[$i][1], $buf, 580; if (not defined $len) { # loop } elsif ($len > 0) { # loop } elsif ($len == 0) { # we're done, end loop #print "read length 0 $pings[$i][0] pid $pings[$i][2]\n"; # if (kill 0, $pings[$i][2]) { # print "process $pings[$i][2] still alive\n"; # kill 9, $pings[$i][2]; # } # readline $pings[$i][1]; close $pings[$i][1]; # waitpid $pings[$i][2], 0; $results{$pings[$i][0]}{status} = $? >> 8; splice @pings, $i, 1; } else { die; } } sleep 1; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: old file descriptors not being cleaned up
by mr_mischief (Monsignor) on Dec 11, 2010 at 03:06 UTC | |
|
Re: old file descriptors not being cleaned up
by Anonyrnous Monk (Hermit) on Dec 11, 2010 at 02:59 UTC | |
|
Re: old file descriptors not being cleaned up
by Khen1950fx (Canon) on Dec 11, 2010 at 03:19 UTC | |
|
Re: old file descriptors not being cleaned up
by wagnerc (Sexton) on Dec 11, 2010 at 16:59 UTC | |
by mr_mischief (Monsignor) on Dec 12, 2010 at 18:48 UTC | |
by wagnerc (Sexton) on Dec 14, 2010 at 01:51 UTC | |
by Anonymous Monk on Dec 14, 2010 at 03:42 UTC | |
by mr_mischief (Monsignor) on Dec 14, 2010 at 17:24 UTC | |
by wagnerc (Sexton) on Dec 15, 2010 at 00:09 UTC | |
|