zerons's Blog

For The Dream

Eudyptula Challenge task01

zerons posted @ 2014年11月30日 19:00 in chanllenge , 1344 阅读

=========================

Write a Linux kernel module, and stand-alone Makefile, that when loaded
prints to the kernel debug log level, "Hello World!"  Be sure to make
the module able to be unloaded as well

=========================

obj-m :=task01.o
KVER := `uname -r`
KDIR = /lib/modules/$(KVER)/build

all:
	make -C $(KDIR) M=`pwd` modules
clean:
	rm -f *.ko *.o *.mod.o *.mod.c *.symvers

 

#include <linux/module.h>

static int task01_init (void)
{
	printk(KERN_INFO "Hello World!\n");
	return 0;
}

static void task01_exit (void)
{
	printk(KERN_INFO "task01 exit...\n");
}

module_init(task01_init);
module_exit(task01_exit);

MODULE_AUTHOR("");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("task01");

 

这样是不符合要求的, 后来查得, 在内核源码目录include/linux/kernel.h(2.6.32.61), include/linux/kern_levels.h(3.17.0)文件中

#define KERN_EMERG	KERN_SOH "0"	/* system is unusable */
#define KERN_ALERT	KERN_SOH "1"	/* action must be taken immediately */
#define KERN_CRIT	KERN_SOH "2"	/* critical conditions */
#define KERN_ERR	KERN_SOH "3"	/* error conditions */
#define KERN_WARNING	KERN_SOH "4"	/* warning conditions */
#define KERN_NOTICE	KERN_SOH "5"	/* normal but significant condition */
#define KERN_INFO	KERN_SOH "6"	/* informational */
#define KERN_DEBUG	KERN_SOH "7"	/* debug-level messages */

共8个级别, 控制台也有一个日志级别console_loglevel, 当printk的输出级别小于console_loglevel时才会显示出来, 详细见http://blog.sina.com.cn/s/blog_4a4832fe0100cvrk.html

 

把源文件中KERN_INFO改成KERN_DEBUG即可

Avatar_small
Bethany 说:
2018年8月31日 15:31

In university my friend help me to the Linux kernel on that time I think that is very difficult. As the time passes I feel it just an easy thing when I follow academic writing services uk review Linux kernel I the famous software everybody knows about it.

Avatar_small
pavzi.com 说:
2024年1月10日 13:57

Pavzi.com provides all the news about Gadgets, the Economy, Technology, Business, Finance and many more. The main concept or our aim behind this website has been the will to provide resources with full information on each topic which can be accessed through the Internet. To ensure that every reader gets what is important and worthy about the topic they search and link to hear from us. pavzi.com Our site is a multiple Niche or category website which will ensure to provide information and resources on each and every topic. Some of the evergreen topics you will see on our website are Career, Job Recruitment, Educational, Technology, Reviews and others. We are targeting mostly so it is true that Tech, Finance, and Product Reviews. The only reason we have started this website is to make this site the need for your daily search use.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter