Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site mddc.UUCP Path: utzoo!watmath!clyde!burl!mgnetp!ihnp4!cbosgd!qusavx!mddc!dale From: dale@mddc.UUCP (Dale Anglin) Newsgroups: net.unix-wizards Subject: Why doesn't this work (fork and pipe problem) ??? Message-ID: <342@mddc.UUCP> Date: Tue, 17-Jul-84 07:23:41 EDT Article-I.D.: mddc.342 Posted: Tue Jul 17 07:23:41 1984 Date-Received: Thu, 19-Jul-84 02:34:50 EDT Organization: MDDC, Cincinnati, Ohio Lines: 77 [] I have a need to read the "who" list into a program buffer. I wrote a test program to verify that it would work. The output of the following program is as expected except that the program seems to hang up in the "read" call. CRT dialog... % cc tst.c -o tst % tst about to read who chris ttyj5 Jul 17 08:15 dale ttyj3 Jul 17 08:31 ... at this point, "tst" does not return to the shell. It can be ^Z'd and ^C'd, but does not terminate as expected. file tst.c cut here ----------------------------------------------- /* *-- Why doesn't this work ??? * * Program is supposed to execute and read the "who" processor output */ main() { int pipefd[2]; int pid; int chkpid; char buffer[100]; pipe(pipefd); switch(pid=fork()) { case -1: /* error */ printf("could not fork\n"); exit(0); case 0: /* child */ 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(0); dup(pipefd[0]); printf("about to read who\n"); while (read(0,buffer,1) == 1) { putchar(buffer[0]); } printf("after who output\n"); while ((chkpid = wait(0)) != pid && chkpid > 0) /* null */; } printf("about to exit\n"); exit(0); } end of file tst.c cut here ---------------------------------------- I was hoping the "read" statement would EOF on the pipe. Any ideas ? Thanks in advance. Dale Anglin Management Decisions Development Corp. 7209 Dixie Highway Fairfield, Ohio 45014 (513) 874-6464 ...{ucbvax,decvax,inhp4,mhuxi}!cbosgd!mddc!dale (uucp)