Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!samsung!spool.mu.edu!munnari.oz.au!uniwa!cc.curtin.edu.au!cutmcvax!corbettm From: corbettm@cutmcvax.cs.curtin.edu.au (Michael Corbett) Newsgroups: comp.sys.sgi Subject: Re: Pipes... Message-ID: Date: 13 May 91 13:23:46 GMT References: <4250.on.Fri,.10.May.91.20:53:34.EDT.@sct60a.sunyct.edu> Sender: news@cutmcvax.cs.curtin.edu.au (Usenet News System) Organization: Curtin University of Technology, Computing Science Lines: 65 Nntp-Posting-Host: cutmcvax.cs.curtin.edu.au sweetmr@SCT60A.SUNYCT.EDU (michael sweet) writes: >In a project I am working on, I want to fork and exec another process with >pipes to *both* the standard input and output of the new process. This will >eventually be used to control the 'tar' program via a GUI. Anyways, my test >programs seems to create the 2 sets of pipes and fork the new program fine, >but when it comes time to actually *write* anything to the standard input of >the second process, the first process sits there waiting t (presumably blocked.) I think the problem is in closing all your pipes. You see a pipe doesn't get passed an EOF until all accesses to the writing end of the pipe have been closed. Someone else had a similar problem on this news group recently. Basically, all you need to ensure is that all the file descriptors open to the write end of your pipes have been close. Obviously, you should also close the read end of the pipe. >The code goes something like this: I have made the changes to the code which I think should work. And marked the additional lines with a <------ > pipe(stdin_pipes); > pipe(stdout_pipes); > child_pid = fork(); > if (child_pid == 0) > { > dup2(stdin_pipes[0], 0); > dup2(stdout_pipes[1], 1); close(stdin_pipes[0]); <------ > close(stdin_pipes[1]); > close(stdout_pipes[0]); close(stdout_pipes[1]); <------ > execlp("/bin/sh", "sh", "-c", command, NULL); > exit(errno); > }; > if (child_id < 0) /* error forking! */ > { > close(all pipes); > } else > { > close(stdin_pipes[0]); > close(stdout_pipes[1]); > child_stdin = fdopen(stdin_pipes[1], "w"); > child_stdout = fdopen(stdout_pipes[0]"r"); close(stdin_pipes[1]); <------ close(stdout_pipes[0]); <------ .... [insert your code] <------ fclose(child_stdin); <------ fclose(child_stdout); <------ > }; [stuff deleted] >me stumped! hope it helps/works :-) -- >> Michael Corbett | "Last night, I thought my arm was << >> corbettm@anger.cipal.cs.curtin.edu.au | hanging out of bed. So I got out << >> corbettm@cutmcvax.cs.curtin.edu.au | to push it in." <<