linux c 定位读取数据pread
来源:互联网 发布:淘宝客服心得体会 编辑:程序博客网 时间:2024/05/18 09:26
今天看代码发现有个 pread,发现这个好用啊。
是一个原子操作,集成了 lseek和read,不会被中断。
NAME pread, read - read from a fileSYNOPSIS #include <unistd.h> ssize_t pread(int fd, void *buf, size_t nbyte, off_t offset); ssize_t read(int fd, void *buf, size_t nbyte);
代码如下:
#include<stdio.h>#include<stdlib.h>#include<fcntl.h>int a=6666;main(){char filename[100];int fd;int data;sprintf(filename,"/proc/%d/mem",getpid());//本程序虚拟内存文件fd=open(filename,O_RDWR);if(fd==-1) printf("open error:%m\n"),exit(-1);pread(fd,&data,4,(off_t)&a); //从虚拟内存的相同地址中,读取实际地址位置相同的数据到data中//pread() = lseek()+read()//lseek(fd,(off_t)&a,SEEK_SET);//read(fd,&data,4); printf("%d\n",data);close(fd);}
阅读全文
0 0
- linux c定位读取数据pread
- linux c 定位读取数据pread
- Linux文件定位读写—lseek、pread、pwrite
- linux编程学习笔记(八) 文件 定位 lseek pread pwrite
- linux编程学习笔记(八) 文件 定位 lseek pread pwrite
- 【C语言】文件定位读取
- C#:读取数据DataReader
- Linux读取串口数据
- C#,大文件读取时快速定位,部分读取
- windows下的ReadFile与Linux下的pread
- Linux系统函数read()/write()/pread()/pwrite()的区别
- Linux基础(五)fread, gets,getchar(),pread,getline(),scanf()
- Linux系统函数read()/write()/pread()/pwrite()的区别
- linux c读取proc
- linux c 读取文件
- linux c读取配置文件
- linux c 读取配置文件
- C语言读取十六进制数据
- 深入HBase架构解析(一)
- 遇到高版本的CAD文件打不开可以这么做
- 字母游戏
- 解决jsp页面乱码问题
- canvas绘图详解-06-绘制一个五角星-常用绘图原理
- linux c 定位读取数据pread
- CVPR2017: Learning Deep Context-aware Features over Body and Latent Parts for
- Android源码编译报错总结
- Python 常用文件格式
- Vue-resource如何实现表单提交以及file图片上传的压缩
- JavaScript中时间戳和日期
- CSS盒子阴影 伪类
- sql的复杂查询步骤
- Spring-boot学习笔记