12-23-06 06:35 AM
In article <1166816672.646553.260570@79g2000cws.googlegroups.com>,
"bnp" <bpisupat@cs.indiana.edu> wrote:
> In my C program, a parent process reads data off from a pipe that is
> written to by its child. In the parent process, I use select operations
> executed in an infinite loop to check if there is data on the pipe to
> be read. The child process generates data and writes it to the pipe.
>
> The issue I am having is that select ALWAYS fails to recognize that
> there is any data available if I set a timeout of less than 10,000
> microsec. If I do set a shorter timeout, select always returns
> indicating that there is not data, which is not true since I know the
> child has executed (based on printf's). Setting larger timeouts (>
> 50000 micros.) solves this problem. Also when I step through the
> program using a debugger, irrespective of the timeouts it works fine.
>
> I am running Linux kernel ver. 2.6.9
>
> Is there a known issue related to this behaviour?
> How can I debug something like this without using a debugger (which
> makes the problem go away)?
If you're using printf() in the child, its output is probably being
buffered. As a result, data will not be available in the parent as soon
as the child calls printf().
What happens if you disable buffering with setbuf() in the child?
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
[ Post a follow-up to this message ]
|