内核热patch

如下代码是一个内核patch

#include <linux/init.h>
#include <linux/module.h>
#include <linux/moduleparam.h>

MODULE_LICENSE("Dual BSD/GPL");

static char *who= "world";
static int times = 1;

module_param(times,int,S_IRUSR);
module_param(who,charp,S_IRUSR);

static int hello_init(void)
{
	int i;
	for(i=0;i<times;i++)
		printk(KERN_ALERT "(%d) hello, %s!\n",i,who);
	return 0;
}

static void hello_exit(void)
{
	printk(KERN_ALERT"Goodbye, %s!\n",who);
}

module_init(hello_init);
module_exit(hello_exit);

编译后,加载该代码用命令

insmod hello who="world" times=5

卸载该代码用

rmmod hello

TODO

学习如何编译
阅读 http://tldp.org/LDP/lkmpg/2.6/html/lkmpg.html

posted on   kramer  阅读(167)  评论(0编辑  收藏  举报

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示