当前位置: 技术问答>linux和unix
老问题,加载最简单的模块,成功了但是没有输出
来源: 互联网 发布时间:2015-08-09
本文导语: #define MODULE #include #include MODULE_LICENSE("GPL"); int int_module(void) {printk("Hello,worldn";return 0;} void cleanup_module(void) {printk("Goodbye cruel worldn");} >gcc -I /usr/src/linux-2.4.20-8/include -c hello.o >insmod hello.o >rmmod hello 加载和卸...
#define MODULE
#include
#include
MODULE_LICENSE("GPL");
int int_module(void) {printk("Hello,worldn";return 0;}
void cleanup_module(void) {printk("Goodbye cruel worldn");}
>gcc -I /usr/src/linux-2.4.20-8/include -c hello.o
>insmod hello.o
>rmmod hello
加载和卸载都没出错,可是怎么就没有输出呢,调用内核的那两个函数白弄了哦
#include
#include
MODULE_LICENSE("GPL");
int int_module(void) {printk("Hello,worldn";return 0;}
void cleanup_module(void) {printk("Goodbye cruel worldn");}
>gcc -I /usr/src/linux-2.4.20-8/include -c hello.o
>insmod hello.o
>rmmod hello
加载和卸载都没出错,可是怎么就没有输出呢,调用内核的那两个函数白弄了哦
|
哈,你和我前两天的疑惑一样,你是在Xwindow环境下开的终端窗口吧,那样是不行的,必须进入黑屏的Linux控制台模式才可以显示输出(这是我自己试出来的,好辛苦啊)。方法:1。按ctrl+alt+f1切换至控制台模式。2。修改inittab,使系统一开机就进入控制台模式
^_^
^_^
|
哥们!这个问题主要是由于你的输出消息级别有问题,如
printk("水电费决死队");
在xwindow的控制台上就看不到!不过可以使用
printk("水电费决死队");
输出,这样就可以看到了!
或者在/proc/log/message这个文件里也可以看到输出!
不知道我说明白了没有!!!
printk("水电费决死队");
在xwindow的控制台上就看不到!不过可以使用
printk("水电费决死队");
输出,这样就可以看到了!
或者在/proc/log/message这个文件里也可以看到输出!
不知道我说明白了没有!!!
|
运行dmesg看看
|
tail -f /var/log/message
|
The output of printk will be not display to console/tty (screen), you can execute the command "dmesg|tail" to check it.
|
谢了npumenglei(雷子)兄,我一直用tty,还在疑惑呢!
|
的确如雷子所说,我刚开始也是遇到了同样的问题,老大给解决的
那次真好玩
老大进了shell就走了
我自己怎么也进不了图形了
就按了reset
呵呵,想起来都好笑
那次真好玩
老大进了shell就走了
我自己怎么也进不了图形了
就按了reset
呵呵,想起来都好笑
|
zfb7901:似乎是放在引号前面吧
|
printk();这个函数有不同的输出级别,不同的输出级别显示的终端设备是不同的,man一下看看就明白了。
|
dmesg
DMESG(8) DMESG(8)
NAME
dmesg - print or control the kernel ring buffer
SYNOPSIS
dmesg [ -c ] [ -n level ] [ -s bufsize ]
DESCRIPTION
dmesg is used to examine or control the kernel ring buffer.
The program helps users to print out their bootup messages. Instead of
copying the messages by hand, the user need only:
dmesg > boot.messages
and mail the boot.messages file to whoever can debug their problem.
OPTIONS
-c Clear the ring buffer contents after printing.
-sbufsize
Use a buffer of size bufsize to query the kernel ring buffer.
This is 16392 by default. (The default kernel syslog buffer
size was 4096 at first, 8192 since 1.3.54, 16384 since 2.1.113.)
If you have set the kernel buffer to be larger than the default
then this option can be used to view the entire buffer.
-nlevel
Set the level at which logging of messages is done to the con-
sole. For example, -n 1 prevents all messages, expect panic
messages, from appearing on the console. All levels of messages
are still written to /proc/kmsg, so syslogd(8) can still be used
to control exactly where kernel messages appear. When the -n
option is used, dmesg will not print or clear the kernel ring
buffer.
When both options are used, only the last option on the command
line will have an effect.
SEE ALSO
syslogd(8)
DMESG(8) DMESG(8)
NAME
dmesg - print or control the kernel ring buffer
SYNOPSIS
dmesg [ -c ] [ -n level ] [ -s bufsize ]
DESCRIPTION
dmesg is used to examine or control the kernel ring buffer.
The program helps users to print out their bootup messages. Instead of
copying the messages by hand, the user need only:
dmesg > boot.messages
and mail the boot.messages file to whoever can debug their problem.
OPTIONS
-c Clear the ring buffer contents after printing.
-sbufsize
Use a buffer of size bufsize to query the kernel ring buffer.
This is 16392 by default. (The default kernel syslog buffer
size was 4096 at first, 8192 since 1.3.54, 16384 since 2.1.113.)
If you have set the kernel buffer to be larger than the default
then this option can be used to view the entire buffer.
-nlevel
Set the level at which logging of messages is done to the con-
sole. For example, -n 1 prevents all messages, expect panic
messages, from appearing on the console. All levels of messages
are still written to /proc/kmsg, so syslogd(8) can still be used
to control exactly where kernel messages appear. When the -n
option is used, dmesg will not print or clear the kernel ring
buffer.
When both options are used, only the last option on the command
line will have an effect.
SEE ALSO
syslogd(8)