<分区>
我正在尝试使用 mmap 打开一个文件: 它在使用 MAP_PRIVATE 时工作正常,但 MAP_SHARED 导致无效参数错误: mmap 文件 ist 读/写
int size;
struct stat s;
const char * file_name = argv[1];
int fd = open (argv[1], O_RDWR);
int pagesize = sysconf(_SC_PAGE_SIZE);
/* Get the size of the file. */
int status = fstat (fd, & s);
size = s.st_size;
size += pagesize-(size%pagesize);
//mmap memory
d = mmap (0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
//error handeling
if(d == -1)
{
perror("mmap");
printf("Error opening file %s\n",argv[1]);
return -1;
}
我做错了什么?