LinuxSir.cn,穿越时空的Linuxsir!

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

内核模块在X下无法输出,在传统终端下就正常

[复制链接]
发表于 2006-7-11 07:14:22 | 显示全部楼层 |阅读模式
  1. /*
  2. * $Id: hello.c,v 1.5 2004/10/26 03:32:21 corbet Exp $
  3. */
  4. #include <linux/init.h>
  5. #include <linux/module.h>
  6. MODULE_LICENSE("Dual BSD/GPL");

  7. static int hello_init(void)
  8. {
  9.         printk(KERN_ALERT "Hello, world\n");
  10.         return 0;
  11. }

  12. static void hello_exit(void)
  13. {
  14.         printk(KERN_ALERT "Goodbye, cruel world\n");
  15. }

  16. module_init(hello_init);
  17. module_exit(hello_exit);
复制代码

这段代码是<Linux device driver>的第一个例子
我在终端下运行一切正常而在X下打开控制台就无法输出任何文字
  1. [root@localhost misc-modules]# insmod hello.ko
  2. [root@localhost misc-modules]# rmmod hello
  3. [root@localhost misc-modules]
复制代码
发表于 2006-7-11 10:16:48 | 显示全部楼层
可能是因为X终端是伪终端的缘故
回复 支持 反对

使用道具 举报

发表于 2006-7-11 12:09:24 | 显示全部楼层
这里有说明:
http://www.faqs.org/docs/kernel/x45.html

1.2.1.2. Using X
It is highly recommended that you type in, compile and load all the examples this guide discusses. It's also highly recommended you do this from a console. You should not be working on this stuff in X.

Modules can't print to the screen like printf() can, but they can log information and warnings, which ends up being printed on your screen, but only on a console. If you insmod a module from an xterm, the information and warnings will be logged, but only to your log files. You won't see it unless you look through your log files. To have immediate access to this information, do all your work from console.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-7-11 15:59:46 | 显示全部楼层
谢谢各位,在网上找了很长时间都找不到答案
回复 支持 反对

使用道具 举报

发表于 2006-7-11 23:52:19 | 显示全部楼层
记得书中在代码的下面就有关于伪终端可能不会产生输出的说明
回复 支持 反对

使用道具 举报

发表于 2006-7-19 20:26:40 | 显示全部楼层
Solaris这点就好得多!直接在X下就可以打开一个Console终端,不知道Linux下为什么不可以
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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