Here is our 1st post on how to add kernel module . execute it, - TopicsExpress



          

Here is our 1st post on how to add kernel module . execute it, have fun. 1. Write a small C program ( Basically a module ) as given below. $vi mymodule.c ================================================ #include #include #include static int __init hello_2_init( void ) { printk( KERN_INFO Hello C world\n ); return 0; } static void __exit hello_2_exit( void ) { printk( KERN_INFO Bye C world\n ); } module_init(hello_2_init); module_exit(hello_2_exit); ================================================ 2. Write a Makefile as shown below. $ vi Makefile ================================================ obj-m += mymodule.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean ================================================ 3. Compile using make utility. $make 4. Insert the module into the kernel. $insmod ./mymodule.ko (Congrats you have written your first kernel module) 5. Check your module code $cat /proc/kmsg $dmesg 6. Check what modules are inserted $cat /proc/modules 7. Check the information about your own module $modinfo ./mymodule.ko 8. Remove the module from the kernel $ rmmod mymodule 9. Check the exit messages $ cat /proc/kmsg $ dmesg 10. Check whether your module has been removed from the kernel $ cat /proc/modules
Posted on: Thu, 20 Mar 2014 19:58:23 +0000

Trending Topics



Recently Viewed Topics




© 2015