#include
/* Defines the license for this LKM */
MODULE_LICENSE("GPL");
/* Init function called on module entry */
int my_module_init( void )
{
printk(KERN_INFO "my_module_init called. Module is now loaded.\n");
return 0;
}
/* Cleanup function called on module exit */
void my_module_cleanup( void )
{
printk(KERN_INFO "my_module_cleanup called. Module is now unloaded.\n");
return;
}
/* Declare entry and exit functions */
module_init( my_module_init );
module_exit( my_module_cleanup );
2. vi Makefile
obj-m += simple-lkm.o
3. build
make -C /usr/src/linux-`uname -r` SUBDIRS=$PWD modules
4. insert module
insmod simple-lkm.ko
5. check module
lsmod
6. check print message
dmesg | tail -5
7. remove module
rmmod simple-lkm
No comments:
Post a Comment