f



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

0
eanbazhagan
8/8/2004 6:30:44 PM
comp.unix.programmer 10827 articles. 0 followers. kokososo56 (349) is leader. Post Follow

2 Replies
1380 Views

Similar Articles

[PageSpeed] 20

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.
0
Chuck
8/9/2004 1:48:00 PM
Reply: