* EAGAIN with read
@ 2007-12-06 20:14 Saurabh Sehgal
2007-12-06 21:29 ` Steve Graegert
0 siblings, 1 reply; 5+ messages in thread
From: Saurabh Sehgal @ 2007-12-06 20:14 UTC (permalink / raw)
To: linux-c-programming
Hi,
I had a basic question about read . I have a file descriptor marked
with non blocking I/O , and I want to read data from the file
descriptor. This file descriptor is the read end of a UNIX pipe.
The process that the pipe reads from is a very slow process. Hence I
need to poll and keep on trying to read from the fd until the process
has actually written something to the pipe. I execute read while the
errno condition EAGAIN is true. Will this ever result in an infinite
loop ? (lets say the remote process dies and doesnt write anything to
the pipe, will I go into an infinite loop since I am polling while
EAGAIN is true ?).
Any help is appreciated. Thank you.
-- S
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: EAGAIN with read
2007-12-06 20:14 EAGAIN with read Saurabh Sehgal
@ 2007-12-06 21:29 ` Steve Graegert
2007-12-06 23:27 ` Saurabh Sehgal
0 siblings, 1 reply; 5+ messages in thread
From: Steve Graegert @ 2007-12-06 21:29 UTC (permalink / raw)
To: Saurabh Sehgal; +Cc: linux-c-programming
On Dec 6, 2007 9:14 PM, Saurabh Sehgal <saurabh.r.s@gmail.com> wrote:
> Hi,
>
> I had a basic question about read . I have a file descriptor marked
> with non blocking I/O , and I want to read data from the file
> descriptor. This file descriptor is the read end of a UNIX pipe.
>
> The process that the pipe reads from is a very slow process. Hence I
> need to poll and keep on trying to read from the fd until the process
> has actually written something to the pipe. I execute read while the
> errno condition EAGAIN is true. Will this ever result in an infinite
> loop ? (lets say the remote process dies and doesnt write anything to
> the pipe, will I go into an infinite loop since I am polling while
> EAGAIN is true ?).
Hi,
I'd suggest taking a look at select(2) which allows for the
specification of a timeout. Use pselect(2) if you are waiting for a
signal as well as data from a file descriptor or otherwise the
select(2) call may block indefinitely due to a nasty race condition
that may occur.
To your question: There are actually a couple of reasons why your
process would or would not run indefinitely in that loop. There are
also a couple of other errors read(3) can return that might cause your
condition to return false, thus breaking the loop (if I understood
correctly, code example is welcome). What about EINTR which is
returned when the call was interrupted by a signal before any data was
read? (Please note that for a FIFO or pipe it will never return EINTR
if any data has been read.)
\Steve
--
Steve Grägert
DigitalEther.de
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: EAGAIN with read
2007-12-06 21:29 ` Steve Graegert
@ 2007-12-06 23:27 ` Saurabh Sehgal
2007-12-08 19:12 ` Steve Graegert
0 siblings, 1 reply; 5+ messages in thread
From: Saurabh Sehgal @ 2007-12-06 23:27 UTC (permalink / raw)
To: Steve Graegert; +Cc: linux-c-programming
Hi,
Thanks for the reply .. right now, i was reading and checking for the
errno EAGAIN, but my loop would prematurely exit. I later found out
that the errnor returned by read was ECHILD ... looking at the read(3)
manpages ... this errno is not mentioned
But since the process that is supposed to write to the pipe is a
forked processs .. does that change anything ?
Thanks,
Saurabh
On Dec 6, 2007 4:29 PM, Steve Graegert <graegerts@gmail.com> wrote:
>
> On Dec 6, 2007 9:14 PM, Saurabh Sehgal <saurabh.r.s@gmail.com> wrote:
> > Hi,
> >
> > I had a basic question about read . I have a file descriptor marked
> > with non blocking I/O , and I want to read data from the file
> > descriptor. This file descriptor is the read end of a UNIX pipe.
> >
> > The process that the pipe reads from is a very slow process. Hence I
> > need to poll and keep on trying to read from the fd until the process
> > has actually written something to the pipe. I execute read while the
> > errno condition EAGAIN is true. Will this ever result in an infinite
> > loop ? (lets say the remote process dies and doesnt write anything to
> > the pipe, will I go into an infinite loop since I am polling while
> > EAGAIN is true ?).
>
> Hi,
>
> I'd suggest taking a look at select(2) which allows for the
> specification of a timeout. Use pselect(2) if you are waiting for a
> signal as well as data from a file descriptor or otherwise the
> select(2) call may block indefinitely due to a nasty race condition
> that may occur.
>
> To your question: There are actually a couple of reasons why your
> process would or would not run indefinitely in that loop. There are
> also a couple of other errors read(3) can return that might cause your
> condition to return false, thus breaking the loop (if I understood
> correctly, code example is welcome). What about EINTR which is
> returned when the call was interrupted by a signal before any data was
> read? (Please note that for a FIFO or pipe it will never return EINTR
> if any data has been read.)
>
> \Steve
>
> --
>
> Steve Grägert
> DigitalEther.de
>
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: EAGAIN with read
2007-12-06 23:27 ` Saurabh Sehgal
@ 2007-12-08 19:12 ` Steve Graegert
2007-12-10 16:21 ` Saurabh Sehgal
0 siblings, 1 reply; 5+ messages in thread
From: Steve Graegert @ 2007-12-08 19:12 UTC (permalink / raw)
To: Saurabh Sehgal; +Cc: linux-c-programming
On Dec 7, 2007 12:27 AM, Saurabh Sehgal <saurabh.r.s@gmail.com> wrote:
> Hi,
>
> Thanks for the reply .. right now, i was reading and checking for the
> errno EAGAIN, but my loop would prematurely exit. I later found out
> that the errnor returned by read was ECHILD ... looking at the read(3)
> manpages ... this errno is not mentioned
>
> But since the process that is supposed to write to the pipe is a
> forked processs .. does that change anything ?
Sorry for the delay...
Looks like you have other problems with your code. I suppose you're
calling wait(2)/waitpid(2)? Could you please post the code in
question? Otherwise I fail to see what could be wrong.
\Steve
PS: Please, do not top post as it makes it diffcult to follow the
conversion. Thanks.
> On Dec 6, 2007 4:29 PM, Steve Graegert <graegerts@gmail.com> wrote:
> >
> > On Dec 6, 2007 9:14 PM, Saurabh Sehgal <saurabh.r.s@gmail.com> wrote:
> > > Hi,
> > >
> > > I had a basic question about read . I have a file descriptor marked
> > > with non blocking I/O , and I want to read data from the file
> > > descriptor. This file descriptor is the read end of a UNIX pipe.
> > >
> > > The process that the pipe reads from is a very slow process. Hence I
> > > need to poll and keep on trying to read from the fd until the process
> > > has actually written something to the pipe. I execute read while the
> > > errno condition EAGAIN is true. Will this ever result in an infinite
> > > loop ? (lets say the remote process dies and doesnt write anything to
> > > the pipe, will I go into an infinite loop since I am polling while
> > > EAGAIN is true ?).
> >
> > Hi,
> >
> > I'd suggest taking a look at select(2) which allows for the
> > specification of a timeout. Use pselect(2) if you are waiting for a
> > signal as well as data from a file descriptor or otherwise the
> > select(2) call may block indefinitely due to a nasty race condition
> > that may occur.
> >
> > To your question: There are actually a couple of reasons why your
> > process would or would not run indefinitely in that loop. There are
> > also a couple of other errors read(3) can return that might cause your
> > condition to return false, thus breaking the loop (if I understood
> > correctly, code example is welcome). What about EINTR which is
> > returned when the call was interrupted by a signal before any data was
> > read? (Please note that for a FIFO or pipe it will never return EINTR
> > if any data has been read.)
> >
> > \Steve
> >
> > --
> >
> > Steve Grägert
> > DigitalEther.de
> >
>
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: EAGAIN with read
2007-12-08 19:12 ` Steve Graegert
@ 2007-12-10 16:21 ` Saurabh Sehgal
0 siblings, 0 replies; 5+ messages in thread
From: Saurabh Sehgal @ 2007-12-10 16:21 UTC (permalink / raw)
To: Steve Graegert; +Cc: linux-c-programming
Hi,
using select solved the problem ... I was not using wait/waitpid ...
it works fine now :) Thanks for all the help. Really appreciate it.
Best Regards,
Saurabh
On Dec 8, 2007 2:12 PM, Steve Graegert <graegerts@gmail.com> wrote:
> On Dec 7, 2007 12:27 AM, Saurabh Sehgal <saurabh.r.s@gmail.com> wrote:
> > Hi,
> >
> > Thanks for the reply .. right now, i was reading and checking for the
> > errno EAGAIN, but my loop would prematurely exit. I later found out
> > that the errnor returned by read was ECHILD ... looking at the read(3)
> > manpages ... this errno is not mentioned
> >
> > But since the process that is supposed to write to the pipe is a
> > forked processs .. does that change anything ?
>
> Sorry for the delay...
>
> Looks like you have other problems with your code. I suppose you're
> calling wait(2)/waitpid(2)? Could you please post the code in
> question? Otherwise I fail to see what could be wrong.
>
> \Steve
>
> PS: Please, do not top post as it makes it diffcult to follow the
> conversion. Thanks.
>
>
> > On Dec 6, 2007 4:29 PM, Steve Graegert <graegerts@gmail.com> wrote:
> > >
> > > On Dec 6, 2007 9:14 PM, Saurabh Sehgal <saurabh.r.s@gmail.com> wrote:
> > > > Hi,
> > > >
> > > > I had a basic question about read . I have a file descriptor marked
> > > > with non blocking I/O , and I want to read data from the file
> > > > descriptor. This file descriptor is the read end of a UNIX pipe.
> > > >
> > > > The process that the pipe reads from is a very slow process. Hence I
> > > > need to poll and keep on trying to read from the fd until the process
> > > > has actually written something to the pipe. I execute read while the
> > > > errno condition EAGAIN is true. Will this ever result in an infinite
> > > > loop ? (lets say the remote process dies and doesnt write anything to
> > > > the pipe, will I go into an infinite loop since I am polling while
> > > > EAGAIN is true ?).
> > >
> > > Hi,
> > >
> > > I'd suggest taking a look at select(2) which allows for the
> > > specification of a timeout. Use pselect(2) if you are waiting for a
> > > signal as well as data from a file descriptor or otherwise the
> > > select(2) call may block indefinitely due to a nasty race condition
> > > that may occur.
> > >
> > > To your question: There are actually a couple of reasons why your
> > > process would or would not run indefinitely in that loop. There are
> > > also a couple of other errors read(3) can return that might cause your
> > > condition to return false, thus breaking the loop (if I understood
> > > correctly, code example is welcome). What about EINTR which is
> > > returned when the call was interrupted by a signal before any data was
> > > read? (Please note that for a FIFO or pipe it will never return EINTR
> > > if any data has been read.)
> > >
> > > \Steve
> > >
> > > --
> > >
> > > Steve Grägert
> > > DigitalEther.de
> > >
> >
>
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-12-10 16:21 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-06 20:14 EAGAIN with read Saurabh Sehgal
2007-12-06 21:29 ` Steve Graegert
2007-12-06 23:27 ` Saurabh Sehgal
2007-12-08 19:12 ` Steve Graegert
2007-12-10 16:21 ` Saurabh Sehgal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).