Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^5: How to tell a child what to do?

by Eyck (Priest)
on Sep 21, 2005 at 11:26 UTC ( #493737=note: print w/ replies, xml ) Need Help??


in reply to Re^4: How to tell a child what to do?
in thread How to tell a child what to do?

Great. This is perfect.

However, I don't know why my version fails, which worries me.

Thanks again, I've got enough to tinker with now.


Comment on Re^5: How to tell a child what to do?
Replies are listed 'Best First'.
Re^6: How to tell a child what to do?
by Anonymous Monk on Sep 21, 2005 at 12:25 UTC
    I've played with the code a bit more, and it's failing for me as well. But not always. How often it fails, depends on the number of spawned children. Trying 1, 2, 3, 4, and 5 children, each 10 times, I get success rates of 100%, 90%, 40%, 10% and 0%.

    Something is wrong, but I do not know what. I'll have to consult Stevens.

      I think, that if you rewrite this with sysread/syswrite, or, like in merlyn's solution with length-based communication, it starts working.

      This may have something to do with perl's buffering, in particular, when instead of while (<>) I wrote this:

      my $q; $q=<STDIN>; print "Received(child $$): $q\n";
      it stopped hanging on close($fd).

      When I traced what is happening when it hangs, it looks like parent is waiting waitpid(..) (close($fd) on pipe is supposed to do that), while child blissfully unaware is running read...

      Now I can safely go and try to understand merlyn's code.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://493737]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (12)
As of 2015-07-28 18:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (258 votes), past polls