[cs631apue] Question about pipe

hyan2 hyan2 at stevens.edu
Sun Dec 16 12:39:23 EST 2012


Thanks for your answer. But the read end of the pipe, say fd1[0], is 
connected to STDIN_FILENO(use dup2()), why I need close fd1[0] after 
dup2(). All of close function is before data communication process not 
after communication. That's why I am confused. By the way, I used two 
pipes connect to child's STDIN_FILENO and STDOUT_FILENO so that parent 
can directly write data(receive from socket) to child's STDIN_FILENO and 
read data from child's STDOUT_FILENO and send it to client. I think one 
pipe is not enough in my program.

On Sun, 16 Dec 2012 10:36:40 -0500, Chao Cui wrote:
> I think the pipe file descriptor with index 1 fd[1] is used for write
> and fd[0] is used for read. If you don't close fd[0] in the read 
> side,
> it will block. That's why your browser will waiting for response.
> Further more, I don't think you need tow pipes. One is enough. You 
> can
> just create one pipe in the parent process. Then you can use it to do
> communication between parent and child.
> See the example in the Book.
>
> Thanks
> Chao
>
> 2012/12/16 hyan2
>
>> Hi Professor,
>>
>> I use pipe for the communication between child process and parent
>> process when I implement POST response. I use two pairs pipe but I
>> find that I must close the other pipe to get the right result. For
>> example, I have two pipe in the child process, one is fd1[2] and one
>> is fd2[2], if I use fd1[0] and fd2[1], then I must close fd1[1] and
>> fd2[0]. In the parent process, I use fd1[1] and fd2[0] and I must
>> close its pairs. If I don't close those pairs I find my browser is
>> waiting for result and when I terminate the server's process, the
>> browser will get the right result. If I close those pairs, every
>> thing is ok. I am confused about this. Could you explain this
>> problem?
>>
>> Thank you.
>>
>> -Han
>> _______________________________________________
>> cs631apue mailing list
>> cs631apue at lists.stevens.edu [1]
>> https://lists.stevens.edu/cgi-bin/mailman/listinfo/cs631apue [2]
>
>
>
> Links:
> ------
> [1] mailto:cs631apue at lists.stevens.edu
> [2] https://lists.stevens.edu/cgi-bin/mailman/listinfo/cs631apue
> [3] mailto:hyan2 at stevens.edu


More information about the cs631apue mailing list