Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!IRO.UMontreal.CA!JSP.UMontreal.CA!gaumondp From: gaumondp@JSP.UMontreal.CA (Gaumond Pierre) Newsgroups: comp.sys.sgi Subject: Problem with pipe/fork Message-ID: <1991Apr16.150557.2344@jsp.umontreal.ca> Date: 16 Apr 91 15:05:57 GMT Sender: news@jsp.umontreal.ca (Administration de C news) Organization: Universite de Montreal Lines: 48 Nntp-Posting-Host: spt3.jsp.umontreal.ca The following program creates a pipe and generates two processes with fork. The parent reads data from standard input and writes it to the pipe. The child reads the pipe and writes data to the standard output. Quite simple. However, it doesn't work. The program reads all the data and everything is transfered (I have tried a small file as a redirection of input). The processes block after the last character is transfered to the standard output. The processes seem to wait for something... for what? EOF? I understood that the "fclose" on the write end of the pipe would generate an EOF status at the read end. Is it correct. Perhaps the problem is somewhere else... ------------------------------------------------------------------------------- main() { FILE *fp; int fdi[2]; char c; pipe(fdi); if (fork()!=0) { /* parent */ fp=fdopen(fdi[1],"w"); for (c=getchar(); !feof(stdin); c=getchar()) fputc(c,fp); fclose(fp); wait(0); } else { /* child */ fp=fdopen(fdi[0],"r"); for (c=fgetc(fp); !feof(fp); c=fgetc(fp)) putchar(c); fclose(fp); } } ------------------------------------------------------------------------------- Pierre Gaumond. -- Pierre Gaumond. | gaumondp@JSP.UMontreal.CA Services Informatiques, Universite de Montreal. | gaumondp@centrcn.UMontreal.CA C.P. 6128, Succursale "A", Montreal, | Quebec, Canada. H3C 3J7 |