Re: children not getting eof from pipe
- From: kspecial@xxxxxxxxxxxxx
- Date: 20 Jun 2005 11:58:32 -0700
btw, here is what I did to make it work, same thing realy, it just
fixes the problem xho mentioned in his first post:
1 use strict;
2
3 my $forks = 5;
4 my (@fd, $num, $oldpid, @results, $read, $write);
5
6 $oldpid = $$;
7 for (undef($num); $num < $forks; $num++) {
8 undef($read); undef($write);
9 pipe($read, $write);
10 select((select($write), $|++)[0]);
11 if (fork) { close($read); $fd[$num][1] = $write } else
{ close($write); last; }
12 }
13
14 if ($oldpid == $$) {
15 for ($a = 0; $a < 100; $a++) { push (@results, $a) }
16 my $num = 0;
17
18 foreach my $result (@results) {
19 print { $fd[$num][1] } "$result" . "\n";
20 $num++;
21 $num = 0 if $num == $forks;
22 }
23 foreach (0..$forks) {
24 close($fd[$_][1]) or die "-!> error closing an
fd\n";
25 }
26 }
27 else {
28 while (chomp(my $data = <$read>)) {
29 print "I'm child $$ with: $data\n";
30 }
31 exit(0);
32 }
kspecial@xzziroz:~$ perl heh.pl
I'm child 4417 with: 0
I'm child 4418 with: 1
I'm child 4419 with: 2
I'm child 4420 with: 3
I'm child 4421 with: 4
I'm child 4417 with: 5
I'm child 4418 with: 6
I'm child 4419 with: 7
I'm child 4420 with: 8
I'm child 4421 with: 9
I'm child 4417 with: 10
I added a sleep (1) after the parent sends to an fd, just so things
happen a lil slower.
This post has been answered and and should be considered closed and
complete.
--K-sPecial
.
- Follow-Ups:
- Re: children not getting eof from pipe
- From: A. Sinan Unur
- Re: children not getting eof from pipe
- References:
- children not getting eof from pipe
- From: kspecial
- Re: children not getting eof from pipe
- From: Jim Gibson
- Re: children not getting eof from pipe
- From: xhoster
- children not getting eof from pipe
- Prev by Date: Re: Net::Telnet and SMTP
- Next by Date: Re: did not produce a valid header
- Previous by thread: Re: children not getting eof from pipe
- Next by thread: Re: children not getting eof from pipe
- Index(es):
Relevant Pages
|
|