日期:2014-05-16  浏览次数:20663 次

菜鸟请教,应用程序如何判断驱动程序已经挂载成功
已经写好驱动hello.ko, init, exit, open函数也已经写好

如果先在控制台"insmod hello.ko"(驱动程序会输出提示信息"install hello.ko")
然后在应用程序里面,

static int fd;
fd = open("/dev/hello",0);(驱动程序提示信息"open hello")
if(fd<0)
{
  exit(1); 
}
是正常打开的


如果在程序里面使用system()函数挂载驱动,就出错了
system("insmod /lib/hello.ko");(驱动程序会输出提示信息"install hello.ko")
fd = open("/dev/hello",0);(这里就没有提示信息了)
if(fd<0)
{
  exit(1); (退出了)
}

应该是system函数还没有完成挂载驱动,open就不能成功

请教高手应该怎么处理呢?
谢谢啊

------解决方案--------------------
fd = open("/dev/hello",0);(这里就没有提示信息了)
if(fd<0)
{
perror("open /dev/hello:");
exit(1); 
}


用perror打出错误原因