It seems that writes/reads to regular files can't not be made non-blocking. I found the following references for support:

from The Linux Programming Interface: A Linux and UNIX System Programming Handbook:

"--- Nonblocking mode can be used with devices (e.g., terminals and pseudoterminals), pipes, FIFOs, and sockets. (Because file descriptors for pipes and sockets are not obtained using open(), we must enable this flag using the fcntl() F_SETFL operation described in Section 5.3.) O_NONBLOCK is generally ignored for regular files, because the kernel buffer cache ensures that I/O on regular files does not block, as described in Section 13.1. However, O_NONBLOCK does have an effect for regular files when mandatory file locking is employed (Section 55.4). ---"

from Advanced Programming in the UNIX Environment 2nd Ed:

"--- We also said that system calls related to disk I/O are not considered slow, even though the read or write of a disk file can block the caller temporarily. ---"

from http://www.remlab.net/op/nonblock.shtml:

"--- Regular files are always readable and they are also always writeable. This is clearly stated in the relevant POSIX specifications. I cannot stress this enough. Putting a regular file in non-blocking has ABSOLUTELY no effects other than changing one bit in the file flags. Reading from a regular file might take a long time. For instance, if it is located on a busy disk, the I/O scheduler might take so much time that the user will notice the application is frozen. Nevertheless, non-blocking mode will not work. It simply will not work. Checking a file for readability or writeability always succeeds immediately. If the system needs time to perform the I/O operation, it will put the task in non-interruptible sleep from the read or write system call. ---"

When memory is adequately available, reads/writes is performed through kernel buffering.

简单来说,对于普通的磁盘文件来说,可读可写条件总是成立的(不像socket缓冲区空了就没法读,缓冲区满了就没法写),所以设置非阻塞模式并没有意义。

问题在于,虽然系统并不认为读/写普通文件会阻塞,可是实际上由于磁盘可能比较繁忙或者比较慢等因素,导致读/写事件延迟很长,同样带来阻塞的问题,

但这种问题却根本无法避免!

O_NONBLOCK on regular file的更多相关文章

  1. scp报错:not a regular file,解决方法:加参数 -r

    命令:scp  -P1234  /data/aa   root@192.0.0..0:/data 文件结构:/data/aa/yearmonth=2015-09 报错:not a regular fi ...

  2. 在linux上使用"scp"命令拷贝一个目录到另一台服务器的时候报"not a regular file"错误的解决办法

    今天在linux命令行使用scp命令拷贝一个目录到另一台服务器的时候,报如下错误: [root@hadoop01 ~]# scp flume -r hadoop02:/root/apps flume: ...

  3. linux,安装软件报错cannot create regular file '/usr/local/man/man1': No such file or directory

    make install时报错,如下 install: cannot create regular file '/usr/local/man/man1': No such file or direct ...

  4. 写交互式脚本时,遇到到报错:not a regular file

    场景:在写两台ubuntu之间需要交互式登录操作shell脚本.就是在ubantu A上,做点什么事,然后远程到ubuntu B上进行操作,shell脚本存放在ubuntu A上. 我遇到这个报错:n ...

  5. scp: /xxxx: not a regular file

    问题描述 scp root@10.2.1.92:/home /home/wangju/databakroot@10.2.1.92's password: xxxxscp: /home: not a r ...

  6. error: can't copy 'docx\templates\default-docx-template': doesn't exist or not a regular file --------------- Failed building wheel for python-docx; python-docx的安装使用;python操作word

    本人第一安装python-docx很不幸就出现了,如下的错误:(如果你也遇到同样的错误,不要慌可以参考下面解决方案,由于第一次处理这种错误,如有不对欢迎大家多多批评指正) 问题所在是因为我们的setu ...

  7. 【APUE】Chapter3 File I/O

    这章主要讲了几类unbuffered I/O函数的用法和设计思路. 3.2 File Descriptors fd本质上是非负整数,当我们执行open或create的时候,kernel向进程返回一个f ...

  8. Java File类总结和FileUtils类

    Java File类总结和FileUtils类 文件存在和类型判断 创建出File类的对象并不代表该路径下有此文件或目录. 用public boolean exists()可以判断文件是否存在. Fi ...

  9. stat file 查看文件的 最新的被访问时间 最近的修改时间 最近的状态改变时间

    [root@NB ~]# stat /media/6FE5-D831/git-data/IT-DOC/web收藏.txt File: `/media/6FE5-D831/git-data/IT-DOC ...

随机推荐

  1. Tiny Rss简明安装与配置笔记

    对于某些自己喜欢的却没有RSS订阅功能的网站,可以通过Feed43定制抓取规则来获取所需信息.但由于其服务器在国外,抓取时常失败,且免费账户抓取频率太低,遂仿造他自行实现了一个并挂到服务器上,然后通过 ...

  2. I18N

    App.config <?xml version="1.0" encoding="utf-8" ?> <configuration> & ...

  3. ArcGIS Javascript查询数据库并添加到地图上

    将数据存放到数据库中,动态的调取比较灵活,数据变动后不需要改变图层的属性表. 此处采用的方法是通过jquery查询数据库,并将数据库的结果生产json串返回给js,在js中动态解析json串增加点至地 ...

  4. [问题2014A01] 复旦高等代数 I(14级)每周一题(第三教学周)

    [问题2014A01]  试求下列 \(n\) 阶行列式的值: \[ |A|=\begin{vmatrix} 1 & x_1(x_1-a) & x_1^2(x_1-a) & \ ...

  5. Oracle的select使用

    1.select : 语法: select [distinct] {*,column [alias],...} from table 注:[]括起来的内容代表可有可无 * 代表所有列 distinct ...

  6. Hibernate配置文件

    <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hi ...

  7. python: 模块发布

    一.准备发布 1.为模块文件创建一个文件夹,并将模块文件复制到这个文件中(一般,文件夹的名字和模块的名字一样) 2.在文件夹中创建一个名为『setup.py』的文件,内容如下: #encoding:u ...

  8. 【PL/SQL系列】Oracle存储过程使用动态SQL

    Oracle存储过程相信大家都比较了解,下面就为您介绍Oracle存储过程使用动态SQL的方法,希望对您能够有所帮助. CREATE OR REPLACE PROCEDURE P_STAT_SCORE ...

  9. Nginx模块之————RTMP模块的FFmpeg的配置问题是FFmpeg的连续退出

    rtmp { server { listen ; application live { allow publish all; allow play all; live on; exec /root/b ...

  10. spring bean的初始化

    scope:作用域   singleton  prototype  request session   默认为singleton lazy-init:default=false ,false ,tru ...