EOF not detected while reading a pipe

I have a problem with implementing pipe in my own shell (written in
C++). Consider the command ls | sort. The child process executes ls (by
fork and exec), writes the output to a pipe(stdout is associated with
it) and parent process executes sort by reading input from the
pipe(stdin of this process is associated with the read end). The
problem is that the parent reads all available data from pipe but it is
still waiting for further data.i.e EOF is not detected by the parent
process. Since the child process is doing exec, I'm not able to close
the pipe in child...How can I solve the problem???

eanbazhagan@rediffmail.com wrote:
> I have a problem with implementing pipe in my own shell (written in
> C++). Consider the command ls | sort. The child process executes ls (by
> fork and exec), writes the output to a pipe(stdout is associated with
> it) and parent process executes sort by reading input from the
> pipe(stdin of this process is associated with the read end). The
> problem is that the parent reads all available data from pipe but it is
> still waiting for further data.i.e EOF is not detected by the parent
> process. Since the child process is doing exec, I'm not able to close
> the pipe in child...How can I solve the problem???
Did the writer close the file ?
Perhaps you can show us some code or even the output of strace ?
G

0

Gianni

8/8/2004 2:37:03 PM

eanbazhagan@rediffmail.com wrote:
> I have a problem with implementing pipe in my own shell (written in
> C++). Consider the command ls | sort. The child process executes ls (by
> fork and exec), writes the output to a pipe(stdout is associated with
> it) and parent process executes sort by reading input from the
> pipe(stdin of this process is associated with the read end). The
> problem is that the parent reads all available data from pipe but it is
> still waiting for further data.i.e EOF is not detected by the parent
> process. Since the child process is doing exec, I'm not able to close
> the pipe in child...How can I solve the problem???
>
It sounds like the write end of the pipe is still being held open by a
process. Are you perhaps creating the pipe in the parent and not
closing the parent's copy of the write end?
-- ced
--
Chuck Dillon
Senior Software Engineer
NimbleGen Systems Inc.