K
kspecial
i've got this issue in where i'm sending data to forked children and
yet they don't want to ever recieve eof() even after the parent closes
the write side. I've looked throughout the camel for any information I
might have missed, but honestly can't seem to locate what it might be.
Maybe if someone here takes a look they will either notice an error or
know a reason.
linux, btw
appreciatively,
yet they don't want to ever recieve eof() even after the parent closes
the write side. I've looked throughout the camel for any information I
might have missed, but honestly can't seem to locate what it might be.
Maybe if someone here takes a look they will either notice an error or
know a reason.
Code:
use strict;
my $forks = 5;
my (@fd, $num, $oldpid, @results, $read, $write);
for (; $num < $forks; $num++) {
my ($read, $write);
pipe($read, $write);
select((select($write), $|++)[0]);
$fd[$num][0] = $read;
$fd[$num][1] = $write;
}
$oldpid = $$;
for (undef($num); $num < $forks; $num++) {
$read = $fd[$num][0];
$write = $fd[$num][1];
if (fork) { close($read); } else { close($write); last; }
}
if ($oldpid == $$) {
for ($a = 0; $a < 100; $a++) { push (@results, $a) }
my $num = 0;
foreach my $result (@results) {
print { $fd[$num][1] } "$result" . "\n";
$num++;
$num = 0 if $num == $forks;
}
foreach (0..$forks) {
close($fd[$_][1]) or die "-!> error closing an fd\n";
}
}
else {
while(!(eof($read))) {
my $data = readline($read);
print "I'm child $$ with: $data";
}
exit(0);
}
linux, btw
appreciatively,