Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 操作系统 > Linux > How to disable the buffer cache of linux fs.
【标  题】:How to disable the buffer cache of linux fs.
【关键字】:How,to,disable,the,buffer,cache,of,linux,fs.
【来  源】:http://blog.chinaunix.net/article.php?articleId=38623&blogId=8818

How to disable the buffer cache of linux fs.

Your Ad Here
try opening the file with O_DIRECT in the flags.
O_DIRECT allows reads and writes to avoid the linux fs cache

举例;

#include <stdio.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

unsigned long long get_sys_time();
int main(int argc,char*argv[])
{
int i;
int nRet=0;
if(argc!=3)
{
printf("Usage:pro file size\n");
return 0;
}
unsigned long long llBeg =0;
unsigned long long llEnd =0;
int fp;
int nLen = atoi(argv[2]);

char *pBuf = (char*)calloc(1,nLen);
llBeg = get_sys_time();
fp = open(argv[1],O_RDONLY,O_DIRECT);
assert(fp>0);
memset(pBuf,0,nLen);
nRet = read(fp,pBuf,nLen);
close(fp);
llEnd = get_sys_time();
free(pBuf);
printf("readed=%d\n",nRet);
printf("elapsed time:=%d\n",(llEnd-llBeg)/1000);
return 0;

}


SLES FAQ -- 到 portal.suse.com 注册激活suse产品:【上一篇】
关于去掉linux打开文件数限制的办法:【下一篇】
【相关文章】
  • Linux下的时间
  • Linux下的进程和线程(待续)
  • linux登陆认证模拟
  • Linux下getch的模拟实现
  • Linux命令-改变文件或目录的访问权限
  • linux操作系统下c语言编程入门
  • linux小系统的构成
  • 修改 linux thread 下单个进程能创建的线程数量的限制
  • Linux系统初学者使用技巧
  • XManager2.0远程连接Linux图形界面
  • 【随机文章】
  • Sharepoint 2007: 用户和权限的使用及疑问
  • JSP+PHP+APACHE+TOMCAT+MYSQL简易配置
  • 数据库安全导读
  • 如何使用JSP+MySQL创建留言本(二)
  • JSP高级编程(1)
  • 小问题出大错,切记要断电后维修
  • 常见的UNIX(Linux)对比
  • 最近把SQL复习了一遍
  • vc6下用gdiplus(gdi+)
  • vb操作电子表格的类
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.