您的位置:首页 > 其它

ldd3 第三章学习感想(1)

2007-09-04 20:10 316 查看
花了两天的 时间把ldd3上的第三章看完了 ,而且还用书上的 例子进行了 调试,不错,例子都调过了,呵呵,书上的 代码都看过了,不过例子代码还没有看完,我想起来了,那上面包含了管道的知识,这应该是 第六章的 知识吧。这段时间总感觉自己linux有些命令不大会,我也不管了,反正到时候边学边用了,只是不懂的 时候多到网上找找就好了。呵呵,脚本和.c程序都是要先编译后,然后用./运行程序名就可以了,而且,本文里只要insmod 就可以,不用运行scull_load 和 scull_unload (现在,这个问题我还没懂,只有在看看书了)。我准备在这三天的时间里 把第四章的知识看完也把第三章的程序读完吧。其实就只有一些数据结构还有点模糊吧。有时间的话就自己写一个驱动,刚好方便第四章的调试。其下是我在网上看到的 一个例子和调试程序,感觉不错,先拷贝下来,等自己写驱动时会有些帮助。在此先谢谢这位仁兄了。
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>

int main(int argc,char *argv[])
{
char *device = "/dev/hello";
int hello_fd;
char cBuffer[100];
char readchar[100];
int i,count;
char * constchar;
constchar = "This is a hello device driver/n";
sprintf(cBuffer,constchar);
printf("driver info is : %s/n",cBuffer);
fflush(stdout);
hello_fd = open(device,O_RDWR);
if(hello_fd == -1)
{
printf("Unable to open hello device!/n");
exit(0);
}
count = write(hello_fd,cBuffer,100);
count = read(hello_fd,readchar,100);
printf("Driver info is : %s/n",readchar);
fflush(stdout);
close(hello_fd);
return 0;
}

另外还有些与本知识块相关的测试链接: http://blog.csdn.net/wooin/archive/2007/08/28/1762818.aspx http://bbs.nju.edu.cn/vd100000/blogcon?userid=qfwqh0396&file=1134566184 http://topic.csdn.net/t/20050615/22/4085312.html gogo 加油!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: