LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 738|回复: 1

read fd error: Bad address

[复制链接]
发表于 2004-5-22 00:45:50 | 显示全部楼层 |阅读模式
  1. #include <unistd.h>
  2. #include <sys/stat.h>
  3. #include <sys/types.h>
  4. #include <syslog.h>
  5. #include <fcntl.h>
  6. #include <stdio.h>
  7. int
  8. main(void)
  9. {
  10.   int   fd,n;
  11.   char  buf[MAXLINE] ;
  12.   if((fd=open("/dev/kmem",O_RDONLY))<0) {
  13.         perror("open /dev/kmem error");
  14.         return(1);
  15.   }
  16.   for( ; ; ) {
  17.         while((n=read(fd,buf,MAXLINE))>0) {
  18.                  if(write(STDOUT_FILENO,buf,n)<0) {
  19.                       perror("write error\n");
  20.                       return(1);
  21.                  }
  22.         }
  23.         if(n<0) {
  24.                 perror("read fd error");
  25.                 return(2);
  26.         }
  27.         memset(buf,'\0',sizeof(buf));
  28.   }
  29.   close(fd);
  30.   return(0);
  31. }
复制代码
# ./getkmem
read fd error: Bad address

请大家看看怎么办? help !
 楼主| 发表于 2004-5-22 17:49:12 | 显示全部楼层
顶!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表