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. pyenv ipython jupyter

    pyenv pyenv  依赖安装 yum -y install git gcc make patch zlib-devel gdbm-devel openssl-devel sqlite-devel ...

  2. 利用javascript实现课程选择

    最终实现的效果如下图所示: 代码如下所示: HTML代码部分: <body> <div class="page" style="overflow: hi ...

  3. JAVA基础知识之NIO——Buffer.Channel,Charset,Channel文件锁

    NIO机制 NIO即NEW IO的意思,是JDK1.4提供的针对旧IO体系进行改进之后的IO,新增了许多新类,放在java.nio包下,并对java.io下许多类进行了修改,以便使用与nio. 在ja ...

  4. Uva 11090 在环中

    题目链接:http://vjudge.net/contest/143318#problem/A 题意: 求平均权值最小的回路. 分析: 平均权值不可能超过最大边,二分查,然后,由于是平均权值,就可以转 ...

  5. ASP.NET多个Button的页面,回车执行按钮事件(转)

    主要有两种实现方法分别是:JavaScript的方法与Panel的方法 一.JavaScript的方法 ①单输入框(文本框)单按钮的实现方法 以下功能实现:在输入框中输入内容之后,按回车键就执行按钮事 ...

  6. java初学知识点

    public class EnumTest { public static void main(String[] args) { Size s=Size.SMALL; Size t=Size.LARG ...

  7. jquery之remove(),detach()方法详解

    一:remove()方法 remove()函数用于从文档中移除匹配的元素. 你还可以使用选择器进一步缩小移除的范围,只移除当前匹配元素中符合指定选择器的部分元素. 与detach()相比,remove ...

  8. Knockout 新版应用开发教程之创建view models与监控属性

    最近抽出点时间研究MVVM,包括司徒正美的avalon,google的angular,以及Knockout,博客园Tom的Knockout指南 时隔2年了,ko更新了不少,所以文档也相应的变化了,所以 ...

  9. struts入门初步(一)

      struts2.0与struts1.0运用了不同的框架,有一定的不兼容性. struts2.0借鉴了webwork的框架思想. Struts2的基本步骤: 1.拷贝struts的jar到项目中(导 ...

  10. js之oop <五>对象序列化(js的JSON操作)

    js对象序列化的过程,就是对象转换为JSON的过程.JSON.stringify() 将对象序列化成JSON.(接收对象,输出字符串) var obj = {x:2,y:3}; var str = J ...