linux c定位读取数据pread

来源:互联网 发布:软件设计师教程txt 编辑:程序博客网 时间:2024/06/08 14:27
#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);}