Re: children not getting eof from pipe



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

.



Relevant Pages

  • Re: Pros & Cons of Daycare
    ... they preschool DS goes to is pretty strict. ... >>3 chances and then get your child expelled when the child really did ... >>innocently fall ill during school. ...
    (misc.kids)
  • [PATCH] tracehook: comment fixes
    ... tracehook: comment fixes ... This fixes some typos and errors in comments. ... This is called immediately after adding @child to its parent's children list. ... * uses the @child pointer; otherwise it might have died and been released by ...
    (Linux-Kernel)
  • Re: Problems forking -- fork DOSes my comp
    ... > use strict; ... you are forking a lot more child than you think! ... start with 1 process, fork: ... sure the child does not go back to fork it's own child: ...
    (perl.beginners)
  • Re: Child DDP Question
    ... They are very strict about making your child order off the child's menu and ... since on the dining plan the child only pays $10.99, ... On the other hand if you have an 'adult' child who would prefer ordering off ... menu whether they are on the dining plan or not. ...
    (rec.arts.disney.parks)