Posted on 2008-11-25 15:31:23-08 by shubhangi
fork-exec in perl
Hi All, I am facing a problem related to fork-exec-pipe sequence in perl on linux. (perl version 5.8.6 on fedora linux) I have a piece of perl code on Sun Solaris system(perl version 5.005_03) which is working absolutely fine. However when I tried the same code on fedora linux it does not work. I am copying the part of the code here:
pipe R1, W1; pipe R2, W2; select((select(W2), $| = 1)[0]); # autoflush output to dotcntl $chld = fork(); if ($chld == 0) { # Child: execute FORTRAN wrapper. print("comes in child \n"); close R1; close W2; open(STDIN, "<&R2"); open(STDERR, ">&W1"); exec("$PSE_HOME/bin/dotcntl") or print("PSE:ERROR Optimizations not installed.\n"), exit 2; } else { # Parent: interact with the wrapper. close W1; close R2; #do the stuff }
here I expect to get the parent executed first and then child repeatedly. It works as expected on SunOS however on linux it executes child first - does nothing, then executes parent and for obvious reasons it hangs. Does anyone have any idea about what's going on here. Waiting for the reply. Thanks, Shubhangi
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.