首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

关于mmap的一个有关问题(一) :(user space)

2012-02-19 
关于mmap的一个问题(一) :(user space)我按照一个linux下c语言函数帮助测试如下源程序,结果没有映射成功,

关于mmap的一个问题(一) :(user space)


我按照一个     linux下c     语言函数     帮助测试如下     源程序,结果没有映射成功,大家帮看下    
 
#include <sys/types.h>    
#include <sys/stat.h>    
#include <fcntl.h>    
#include <unistd.h>    
#include <sys/mman.h>    
main()    
{    
int     fd;    
void     *start;    
struct     stat     sb;    
fd=open( "/etc/passwd ",O_RDONLY);     /*open     /etc/passwd     */    
printf( "fd     =     %d     \n ",     fd);    
fstat(fd,&sb);     /*get     file     size/    
start=mmap(NULL,sb.st_size,PROT_READ,MAP_PRIVATE,fd,0);    
if(start     ==     MAP_FAILED)     /*check     that     map     is     ok*/    
{    
      printf( "mmap     failed!!\n ");    
      return;    
}    
printf( "%s ",start);    
munma(start,sb.st_size);     /*unmap*/    
closed(fd);    
}    
 
 
平台是     redhat的         AS4,     编译通过,     运行输出如下:    
 
[root@112     test]#     gcc     mmap.c     -o     mmap                                                                                                                                                                                
[root@112     test]#     ./mmap        
fd     =     3        
mmap     failed!!    
[root@112     test]#    



[解决办法]
munma => munmap
closed => close

我不知道你参考的什么东西,不过参考的东西实在是太烂了。

还有 /etc/passwd 不是随便可以map的,需要权限。
[解决办法]
[root@112 test]# root权限还不够啊??
[解决办法]
你咋会 mmap 那个文件呢。。 好奇怪啊。。

[解决办法]
可以出来啊
你的这个很正常
你file /etc/passwd一下
我的是ASCI

热点排行