[comp.sys.apollo] RE> problem with pipe/fork

mathys@dover.sps.mot.com (Yves Mathys) (04/17/91)

>> From: gaumondp@JSP.UMontreal.CA (Gaumond Pierre)
>> Subject: Problem with pipe/fork

>> 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...



 A good pratice is to close all unused pipe descriptors so the close
 statement can effectively close the file descriptor. 
 Closing fdi[0] and fdi[1] respectively in the parent and child will
 fix your problem.

/*parent */
close(fdi[0]) ; 
fp= fopen(...) ... 

/*child */
close(fdi[1]) ; 
...


		Yves Mathys 
		mathys@dover.sps.mot.com
		Motorola Inc (Arizona)
--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
	Yves Mathys
	Motorola Inc/Sector CAD
	mathys@scad.sps.mot.com