I have two programs, call them "A" and "B." Program B produces output periodically, and program A opens a pipe for reading to catch the output. The problem is that if there's no output to be read at that particular moment, the call to read hangs until there is, all the while program A is completely unresponsive. What's the simplest, most efficient way to tell whether or not an opened pipe has data to be read, before calling read() or sysread() on it?