c - c中的mmap errno 22读取openmpi数据类型说明
问题描述
我正在使用 mmap 从文件中读取。
mmap 返回 errno 22,无效参数。
在这种情况下 stat.st_size 是 400 我不认为它“太大”。
我认为我没有遇到“我们不喜欢 addr、length 或 offset”。
我在 Intel Xeon E5 上运行这个程序(我认为它不相关)。
我在这里想念什么?
if( argc > 1 ) {
struct stat stat;
for( int i = 1; i < argc; i++ ) {
if( access(argv[i], R_OK) == -1 ) {
printf("\n Cannot access datatype description file %s\n", argv[i]);
continue;
}
int fd = open(argv[i], O_RDONLY);
if( fd == -1 ) {
printf("\n Cannot open datatype description from file %s\n", argv[i]);
continue;
}
if( fstat(fd, &stat) == -1 ) {
printf("\n Cannot stat the %s file\n", argv[i]);
continue;
}
void* addr = mmap(NULL, stat.st_size, PROT_READ, MAP_FILE, fd, 0);
if( MAP_FAILED == addr ) {
printf("\nCannot map the datatype description file %s\n", argv[i]);
printf("%s %d stat.st_size %d\n", strerror(errno), errno, stat.st_size );
perror("mmap");
close(fd);
continue;
}
munmap(addr, stat.st_size);
free(addr);
close(fd);
}
}
解决方案
来自man 2 mmap
:
MAP_FILE
Compatibility flag. Ignored.
...
EINVAL flags contained neither MAP_PRIVATE or MAP_SHARED, or contained
both of these values.
您需要通过其中一个MAP_PRIVATE
or MAP_SHARED
,并且您应该停止通过MAP_FILE
。(你甚至认为它做了什么?)
推荐阅读
- java - Spring CommandLineRunner 不使用 WAR 类依赖项运行
- r - 删除闪亮的仪表板标题和传单地图之间的空白
- python - 如何移动/移动/平移重叠的几何图形?
- css - Edge 中的 SVG 溢出不可见
- r - R Shiny:在动态情况下有条件地更新可能的用户输入选择
- c++11 - 不匹配 operator+ ,也不匹配 c++ 中的向量构造调用
- nginx - 为什么网站不使用 nginx 重定向
- vim - vim 颜色方案无法正确显示
- python - 从 Keras 中经过训练的自动编码器模型中获取解码器
- python - 如何排序此列表,最低开始时间首先显示