Help on nonblocking read & write with popen4

Hi all,
Any hint on using popen4 for alternate reading and writing to a pipe?
Especially, how to avoid blocking on reading from stdout,stderr.
An example will be much appreciated.

Thanx in advance,
Masgad