"Gauri" <> 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