Home > Archive > Unix Programming > September 2005 > opening a fiile with O_NONBLOCK
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
opening a fiile with O_NONBLOCK
|
|
| junky_fellow@yahoo.co.in 2005-09-27, 7:57 am |
| Is the O_NONBLOCK option supported for regular files ?
What happens if some file (for which O_NONBLOCK option is
supported) is opened with O_NONBLOCK and a read is done
on this file and no data is available. Does the read is
guaranteed to return some error Or the return value is implementation
specific ?
Thanx for any help in advance ...
| |
| Barry Margolin 2005-09-27, 9:57 pm |
| In article <1127816036.043468.116200@g47g2000cwa.googlegroups.com>,
junky_fellow@yahoo.co.in wrote:
> Is the O_NONBLOCK option supported for regular files ?
It's allowed, but it has no effect, because reading a regular file never
blocks.
>
> What happens if some file (for which O_NONBLOCK option is
> supported) is opened with O_NONBLOCK and a read is done
> on this file and no data is available. Does the read is
> guaranteed to return some error Or the return value is implementation
> specific ?
If there's no data available, you must be at the end of the file, so
read() returns 0 immediately to indicate EOF. It doesn't block when you
don't use O_NONBLOCK, so it doesn't return an error with errno =
EWOULDBLOCK when you use O_NONBLOCK.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
| |
| junky_fellow@yahoo.co.in 2005-09-28, 3:58 am |
|
Barry Margolin wrote:
> In article <1127816036.043468.116200@g47g2000cwa.googlegroups.com>,
> junky_fellow@yahoo.co.in wrote:
>
>
> It's allowed, but it has no effect, because reading a regular file never
> blocks.
>
If a process P1 has taken a mandatory write lock on a file and some
other process P2 does read operation on that file it would block.
If the process P2 would have opened the file with O_NONBLOCK option
it would return with error EWOULDBLOCK.
| |
| Villy Kruse 2005-09-28, 3:58 am |
| On Tue, 27 Sep 2005 21:34:39 -0400,
Barry Margolin <barmar@alum.mit.edu> wrote:
> In article <1127816036.043468.116200@g47g2000cwa.googlegroups.com>,
> junky_fellow@yahoo.co.in wrote:
>
>
> It's allowed, but it has no effect, because reading a regular file never
> blocks.
>
If data has to be retreived from a disk or file server the process must
block until the data becomes available. If the disk systems gets too
busy then it can happen that the process will be blocked for quite a while,
and if the file is on a crashed NFS server the process will even block
for ever. In either case the blocking is non-interruptible meaning
that not even kill -9 can touch the process.
Villy
| |
| Nils O. Selåsdal 2005-09-28, 3:58 am |
| Villy Kruse wrote:
> On Tue, 27 Sep 2005 21:34:39 -0400,
> Barry Margolin <barmar@alum.mit.edu> wrote:
>
>
>
>
>
> If data has to be retreived from a disk or file server the process must
> block until the data becomes available. If the disk systems gets too
> busy then it can happen that the process will be blocked for quite a while,
> and if the file is on a crashed NFS server the process will even block
> for ever. In either case the blocking is non-interruptible meaning
> that not even kill -9 can touch the process.
Yes, but unix kernels traditionally doesn't signal that an IO call will
block on "normal" files. Ofcourse, reading can block on regular files,
the filesystem might be busy and not honor the read/write request for a
time, it's just that O_NONBLOCK doesn't have any effect, and the io
calls still blocks. (save perhaps mandatory locks on some platforms.)
|
|
|
|
|