... when the child process stops giving output the while (<READ>) terminates ...
No it doesn't! That's the point.
Unless the child process closes the file handle, and so signals that it's not going to write any more output, while( <READ> ) { ... } will just wait until it writes some more.
Since you are running the child process continuously, it never closes stdout, so the parent's inner read loop will never terminate. Sorry, but that is just the way it is.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] |
Ok I get what you are saying now. If this is the case how come the program hangs at random iterations of the loop usually something around 3500 even up to 5000, and at the same command every time? Also the program ran fine in Unix the way it is now.
| [reply] |
If this is the case ...
It is. Regardless of the OS.
... how come ...
Best guess. The pseudo-code you are posting is a poor reflection of what your real code is actually doing.
I understand that you have good reasons for not posting the real code, so here is a suggestion. Make a copy of the real code and cut it down to just the outer and inner loops you are concerned with. Then substitute the perl 'echo' command from my post above:
my $pid = open2 \*READ, \*WRITE, 'perl -wne "$|++; chomp; print"';
Run that. It should demonstrate the same behaviours as your real program, though the iterations counts will differ. Once you have verified that it has similar problems, post it here.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] |