内核热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 2019-07-22 11:02  kramer  阅读(165)  评论(0编辑  收藏  举报

导航