Heat kernel patch

The following code is a kernel 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);

After compilation, loading the code with the command

insmod hello who="world" times=5

Uninstall the code with the

rmmod hello

ALL

Learn how to compile
reading http://tldp.org/LDP/lkmpg/2.6/html/lkmpg.html

Guess you like

Origin www.cnblogs.com/kramer/p/11224612.html