Re: Parent process unable to read messages from child process



Hi,
I appreciate the quick response.

Apologies for the typo--
The statement in the main code is:
foreach $uncompclient($selectpipe->can_read){


my @filedetail = map {<$_>} @list_of_child_handles;
Could you please explain series of blocking read in details with
respect to my code?

-Thanks a lot.

-Regards,
Gauri



On Feb 28, 2:09 pm, xhos...@xxxxxxxxx wrote:
"Gauri" <himaga...@xxxxxxxxx> wrote:
Hello,

I've a process which is supposed to do the following:
1.A Parent process has to fork to create fixed number of child
processes. (This fixed number changes each time my code runs.)
2. Each child computes certain values and writes these values on to a
pipe.
3. The parent should read each of these values from pipe output of all
children and store them in a global variable to be used later in the
process.

Fork work correct, Child processes compute the correct value, however
Parent is unable to read output of all children. For e.g. when 3
children are created, one child completes execution first, and parent
is able to read it's value. The other two processes complete 20
seconds later and exit immediately one after the other. The parent is
unable to read the values of the 2nd and 3rd child.

First of all, you should be using strict and warnings. If you did
so, it probably would have helped you identify the problem.

$count = 0;
while(1){
foreach my $client ($selectpipe->can_read) {
$filedetail[$count] = <$uncompclient>;
$count++;
}
}

Since $client is what can_read returned, you should be reading from
$client, not $uncompclient, which seems to be used no where else and
so probably undefined. You also need to remove the handle from $selectpipe
once it reaches eof. And you probably shouldn't mix <> and read on the
same handles you are using Select on.

And since your code doesn't do anything meaningful until all the children
are done anyway, there is really no reason to use IO::Select at all. Just
keep a list of the file handles and do a series of blocking reads on them:

my @filedetail = map {<$_>} @list_of_child_handles;

Xho

--
--------------------http://NewsReader.Com/--------------------
Usenet Newsgroup Service $9.95/Month 30GB- Hide quoted text -

- Show quoted text -


.



Relevant Pages

  • Why cant I convince this piece of code to run???
    ... foreach $child { ... unless ($pid = fork()) { ... # Parent process - loop to start others ...
    (perl.beginners)
  • Re: Trying to understand this forking open stuff...
    ... parent starts: Wed Nov 8 13:45:14 2006 ... child starts: Wed Nov 8 13:45:14 2006 ... statements don't do execute until after the parent process is over. ... Look carefully at the times displayed, it is not blocking. ...
    (perl.beginners)
  • Re: Writing from a parant process to two child processes
    ... opened and the parent writes to the appropriate pipe. ... a child via exit. ... have been closed (so the child is blocking on a read). ...
    (comp.os.linux.development.apps)
  • Re: How to iterate throut an array?
    ... Foreach is not a good solution in this task. ... Let's say I have an array: ... When I do foreach I cannot say what's the value of a parent or child of ...
    (comp.lang.php)
  • Unix Programming FAQ (v1.37)
    ... Why use _exit rather than exit in the child branch of a fork? ... Why doesn't my process get SIGHUP when its parent dies? ... How do I create a named pipe? ... How do I compare strings using regular expressions? ...
    (comp.unix.programmer)