timeout problems while using select with pipes
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > timeout problems while using select with pipes




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    timeout problems while using select with pipes  
bnp


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-23-06 12:21 AM

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)?






[ Post a follow-up to this message ]



    Re: timeout problems while using select with pipes  
Barry Margolin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
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 ]



    Re: timeout problems while using select with pipes  
bnp


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-23-06 06:33 PM


> What happens if you disable buffering with setbuf() in the child?

Buffering certainly was an issue (I should have thought of that). But
interestingly,  using unbuffered writes to the pipes reduces the
minimum select timeout for seeing the 'right' behaviour to 1000 msec.
Setting the timeout to be anything less than this means that select
again fails to recognize that there is data available to be read.

Also 1000msec is the consistent number I see across different machines,
and even on a Solaris box.






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:14 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register