in reply to Re^5: forking and monitoring processes
in thread forking and monitoring processes

Hello revdiablo,

Thanks for the reply. That helped understand so many things better. I changed all the things you suggested, but it still seems that the program does not enter the while loop. I even changed the hash code as you suggested, but that did not seem to be the problem. What do you advice?

Thanks.

use IO::Select; my %pids; my $s = IO::Select->new(); my @proc = (qw(C W)); for ( @proc ) { my $pid = open my $fh, "dir $_: |" or warn "Could not fork&open $cmd: $!" and next; print "opened $_ \n\n"; $pids{$fh} = [ $pid, $_ ]; $s->add($fh); } while (my @ready = $s->can_read) { print "entered while loop \n\n"; for my $fh (@ready) { if (eof $fh) { delete $pids{$fh}; $s->remove($fh); next; } my $line = <$fh>; if ($line =~ /Windows/) { chomp $line; print "Found 'Windows' in '$line' from $pids{$fh}[1]\n"; kill 15, map { $_->[0]} values %pids; } } }