O_NDELAY and reading pipes

Robert E. Stampfli res at cbnews.ATT.COM
Tue Jan 16 05:34:19 AEST 1990


OK, here is another query for you experts:  I have a program which cannot
suspend, and which must acquire data from a subprocess.  So I create a pipe
and use it to pass the information from the subprocess to the main program.
In the main program I use fcntl() to set the O_NDELAY option on the read
fd of the pipe and then periodically poll it.  All is fine and good -- the
read() syscall returns zero if there is no data in the pipe -- until the
subprocess terminates.  Now my dilemma:  How do I detect this?  The reading
process keeps on seeing read() return zero.  It seems logical that
there ought to be some difference in response between polling a pipe that is
active, but with no data, and one where the write end has been closed.  I
cannot figure how to do this, though, except thru gross means (remove O_NDELAY
and read with a signal to interrupt a potential hang).  

Any suggestions?  I'm talking SVR2.

BTW, I tried using kill(pid, 0) to ascertain the aliveness of the subprocess,
but this doesn't yield any useful information, either, as the subprocess
becomes a zombie on death, but kill() still shows it as existing.
-- 
Rob Stampfli	/ att.com!stampfli (uucp at work) / kd8wk at w8cqk (packet radio)
614-864-9377	/ osu-cis.cis.ohio-state.edu!kd8wk!res (uucp at home)



More information about the Comp.unix.questions mailing list