Re: Programming Question: non-blocking I/O

From: Robert Heller (heller_at_deepsoft.com)
Date: 04/06/04


Date: Tue, 06 Apr 2004 01:50:56 +0200


  donm@calculex.com (Don M),
  In a message on 5 Apr 2004 09:21:15 -0700, wrote :

DM> I'm porting an app from Windows to Linux and have not yet found how to
DM> do non-blocking I/O on a file (aka asynchronous or "overlapped" I/O).
DM>
DM> Under Windows, you call WriteFile() and pass it an Event which you
DM> later pass to a wait function when you run out of other things to do.
DM> How is this done under Linux?
DM>
DM> I've found reference to two flags O_ASYNC and O_NONBLOCK on the man
DM> page for open(), but these don't appear to be applicable to regular
DM> files.

They are not.

The thing is this: *Originally* (eg Win 3.11) Windows was a cooperative
'multi-'tasking operating system. There was not either a 'real' kernel
now any sort of background processing for disk I/O. Early versions of
Windows 'faked' this.

Under UNIX (and Linux), *actual* disk I/O (low-level I/O) is handled via
various background tasks in the kernel. From a user-level process, disk
I/O is always synchronous and effectively instantaneous -- user process
don't every actually wait for the bits to fully land on the disk
platters. The bits end up in a disk cache buffer and are flushed to the
disk platters sometime later (usually in a few seconds or the next time
there are no jobs in the run queue or some process invokes the sync
command).

The only time you use O_ASYNC or O_NONBLOCK is for slow I/O devices
(serial ports, parallel ports, keyboards, etc.) and for things like
pipes and sockets (network).

DM>
DM> Thanks,
DM> Don
DM>

                                     \/
Robert Heller ||InterNet: heller@cs.umass.edu
http://vis-www.cs.umass.edu/~heller || heller@deepsoft.com
http://www.deepsoft.com /\FidoNet: 1:321/153

           



Relevant Pages

  • RE: [SLE] Need help recovering my Linux System
    ... >>would I want Windows on my other machine? ... I have the full backup of my old system on a usb disk ... I have never worked with setting up a usb connection on Linux. ... Windows partition ahead of both of my swap and my data partition. ...
    (SuSE)
  • Re: Well, Windows is back on the disk.
    ... So your saying that Microsoft makes billions monthly because people DESIRE ... I am too fracking lazy to teach myself the intricacies of Linux. ... All of the WINDOWS operating systems and office products are upgradeable to the latest security fixes and bug fixes. ... OS problems overwrites all personal files on the disk. ...
    (Ubuntu)
  • Re: Equivalent utilities?
    ... All this about how nice Linux is and "don't worry" etc etc. ... Windows tend to do it at all times, ... Linux will normally manage/handle disk fragmentation but!!! ...
    (alt.os.linux)
  • Re: Linux, BSD, and Unix are fundamentally insecure.
    ... > machine and passed a command to GRUB that booted linux into the BASH ... Someone can just take the Linux disk out, ... > Windows doesn't have this flaw. ... > the disk out and trying to mount it using another OS. ...
    (comp.unix.bsd.freebsd.misc)
  • Re: Linux, BSD, and Unix are fundamentally insecure.
    ... > machine and passed a command to GRUB that booted linux into the BASH ... Someone can just take the Linux disk out, ... > Windows doesn't have this flaw. ... > the disk out and trying to mount it using another OS. ...
    (comp.unix.bsd.openbsd.misc)