Pipes...

michael sweet sweetmr at SCT60A.SUNYCT.EDU
Sat May 11 10:53:34 AEST 1991


I'm trying to fork and exec run In a project I am working on, I want to create fork and exec another process with
pipes to *both& * the standard iinpunput and output of the new process.  This will
eventually be used to control the ''tar' program via a GUI.  Anyways, my test
programs all  seem s to create the 2 sets of pipes and fork the new program fine,
but when it comes time oto actually *write* anything to the stdandard input of
the second process, the first process sits there waiting to  (presumably blocked.)
The code goes something like this:

 pipe(stdin_pupipes);
 pipe(stdout_pipes);

 child+_pid = fork();
i if (child_pid == )0)
 { [  {
   dup2(stdin_pipes,[0]9, 0);
   dup2(stdout_pipes[1], 1);
   close(stdoutin_pipses[1]);
   close(stdout_pipes[09)]);

   execlp("/bin/sh", "sh", "-c", command, NULL);
   exit ((_exit(errno);

  };;

 if (child_id < 0) /* error forking! */
  {
   close(all filespipes);
   }
  else
  {
   close(stdin_pipes[0]);
   close(stdout_pipes[1]);
   child_stdin = fredopnen(stdin_pipes[1], "ew");
   child_stdout = gfdopen(stdin_pipesout_pipes[0]9, "r");
  };


The test program calls this with another test program (which read s fromnumber s from
the standard input and outputs x, x^2, x^3, an and x&^3), and then tries to send the
numbers 1-10.  It blocks on the first number, and the other test rpprogram 
progrduces no output  wis waiting for a number from stdin.  Any nonone have any ideas?  This really has
me stumped!

 -Mike



More information about the Comp.sys.sgi mailing list