Why doesn't this work (fork and pipe problem) ???

Toby Harness toby at gargoyle.UChicago.UUCP
Thu Jul 19 04:08:24 AEST 1984


(sorry, but I can`t seem to reply)

Well, you didn`t close the 'unused' sides of the pipe.

	pipe(pipefd);

	switch(pid=fork())
	...
	case 0:					/* child */
========>   close(pipefd[0]);	/* not necessary, just good practice */
	    close(1);
	    dup(pipefd[1]);
	    printf("about to exec who\n"); 
	    execlp("/bin/who", "who", (char*)0);
	    printf("could not execute\n");
	    exit(0);

	default:				/* parent */
========>   close (pipefd[1]);	/* necessary */
	    close(0);
	    dup(pipefd[0]);
	...

Toby Harness		Ogburn/Stouffer Center, University of Chicago
			...ihnp4!gargoyle!toby



More information about the Comp.unix.wizards mailing list