Let's say I spawn a process PO through popen
(READ ONLY) from a process PA. I then pclose()
the pipe on PA's side.
On PO's side, how do I determine if stdout is still available without executing a write()
?
Note that I have tried catching SIGPIPE on PO's side to no avail.
UPDATED: I tried using fstat(1, &buf)
without success.
UPDATED: The reason I need to detect this condition through PO I do not have access to PO's PID from PA (and hence can't kill it). Futhermore, I'd like for PO to be more robust in face failures of PA i.e. exiting by itself.
RESOLUTION: I went ahead and used socketpair
, fork
. Trying to control a process through popen
turned out to be a nightmare (to me at least). A big thanks to everyone who contributed!