This problem occurs on both Free BSD and Linux.
I have a parent-child situation, where the parent creates two pipes,
and then forks(), then the child exec's a sort. The parent then reads
the pipe to get the sorted output. SO...
parent:
establishes 2 pipes pfd1 and pfd2 which have both read and
write ends. Parent writes records to The write end of the
pipe connected to STDIN of the child.
child:
dup2() the pipe ends, the read end of pfd1 to STDIN and the write end
of pfd2 to STDOUT. The child then execlp() /usr/bin/sort -n.
Sort reads the input, does it's thing, then writes the output. The
parent reads the pfd2 read end, and manipulates the sorted output.
The problem is, I never see the EOF on the sorted output.
I found that the read loop in the parent could terminate on a
waitpid() or by using a signal handler for SIGCHLD, and a variable
shared between the signal handler and the parent code, I could
terminate the read loop. But I never saw the read() terminate with a
count of 0 indicating EOF.
Since this situation behaved uniformly over Linux, FreeBSD current,
and dragonfly-BSD, I suspect I am running into a subtlety that is
architected.
Anybody got any clues for me?
--
Derek Tattersall | Nothing cures insomnia like the realization that
| it's time to get up.
dlt@mebtel.net |
|
dlt666@yahoo.com |
|
|
0
|
|
|
|
Reply
|
Derek
|
10/18/2004 8:10:36 PM |
|
In article <868ya3hjnn.fsf@lapdog.arm.org>,
Derek Tattersall <dlt@mebtel.net> wrote:
> This problem occurs on both Free BSD and Linux.
>
> I have a parent-child situation, where the parent creates two pipes,
> and then forks(), then the child exec's a sort. The parent then reads
> the pipe to get the sorted output. SO...
>
> parent:
> establishes 2 pipes pfd1 and pfd2 which have both read and
> write ends. Parent writes records to The write end of the
> pipe connected to STDIN of the child.
>
> child:
> dup2() the pipe ends, the read end of pfd1 to STDIN and the write end
> of pfd2 to STDOUT. The child then execlp() /usr/bin/sort -n.
> Sort reads the input, does it's thing, then writes the output. The
> parent reads the pfd2 read end, and manipulates the sorted output.
>
> The problem is, I never see the EOF on the sorted output.
>
You need to make sure the parent and child close the ends of each
pipe they are not using. The read end of the pipe will not return EOF
until all of the write ends have been closed.
Cheers,
- jonathan
P.S. You should note that this is generally a dangerous construct (since
you can easily deadlock, due to the limited kernel input buffers), but
since sort(1) usually has to read all of its input before having any
output, it's not a problem in this case.
|
|
0
|
|
|
|
Reply
|
Jonathan
|
10/18/2004 8:57:15 PM
|
|
|
1 Replies
513 Views
(page loaded in 0.016 seconds)
Similiar Articles: EOF on pipe - comp.unix.programmerThis problem occurs on both Free BSD and Linux. I have a parent-child situation, where the parent creates two pipes, and then forks(), then the chil... EOF not detected while reading a pipe - comp.unix.programmer ...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 e... manually flush stdout pipe? - comp.unix.shellEOF on pipe - comp.unix.programmer EOF on pipe - comp.unix.programmer manually flush stdout pipe? - comp.unix.shell Sending an EOF to a named pipe - comp ... couldn't create pipe: too many open files - comp.lang.tcl ...EOF not detected while reading a pipe - comp.unix.programmer ... EOF on pipe - comp.unix.programmer EOF not detected while reading a pipe - comp.unix.programmer ... bidirectional pipe question - comp.lang.tclHi, I am using a bidirectional pipe to filter data through a Unix command, but for some commands it hangs forever. I suspect that the command is waiting for an EOF ... Pipes - Named or Anonymous - comp.os.ms-windows.programmer.win32 ...EOF on pipe - comp.unix.programmer Pipes - Named or Anonymous - comp.os.ms-windows.programmer.win32 ... EOF on pipe - comp.unix.programmer manually flush stdout pipe ... pipe error: "too many open files" - comp.unix.programmer ...EOF error. - comp.lang.vhdl Torrentflux B4rt Script :: Pipe Error: Too Many Open Files In System Broken Pipe Error ... EOF not detected while reading a pipe - comp.unix ... tar terminates unexpectedly when piped to dd ? - comp.os.linux ...when making the script, I thought only the last "BLOCKS" input block could be read incompletely, that is when dd received an EOF through the pipe. MIDI over Internet... - comp.music.midiEOF on pipe - comp.unix.programmer MIDI over Internet... - comp.music.midi... might be useful to pipe remarks made by your synth back to kbdhost, for example. create tar from stdin - comp.unix.adminEOF on pipe - comp.unix.programmer... dup2() the pipe ends, the read end of pfd1 to STDIN and ... > You need to make sure the parent and child close the ... tar ... Unix & Linux: EOF on pipe - programming.itags.orgprogramming.itags.org: Unix & Linux question: EOF on pipe, created at:Wed, 30 Apr 2008 09:46:00 GMT with 1,442 bytes, last updated: Thursday, July 05, 2012, 1 Answers. Sending an EOF to a named pipe - Unix Linux Forum - Fixunix.comI'm using named pipes in a bash script and I can't figure out how to send an EOF so that the reader can exit. I tried the obvious: echo -e 7/22/2012 3:04:07 AM
|