- 论坛徽章:
- 0
|
各位大侠,小弟最近在学习linux下的编程,在进行一个mmap实验程序的时候,出现了bus error这个错误,百思不得其解,望各位大侠指教:
// receiver.c
#include <stdio.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <string.h>
const int SIZE = 100;
void main() {
int i;
int fd = open("./block", O_RDWR, 0666);
if(fd < 0) {
perror("open failed");
return;
}
//Now map this file to memory
caddr_t addr = mmap(0, SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if(addr <= 0) {
perror("mmap failed");
return;
}
printf("%s\n",addr);
}
注:这个程序刚开始运行时还好好的,后来改了一下,出现错误,又改回来,就出现bus error了!
运行环境:virtualbox 上的ubuntu13.04 |
|