Tuesday, October 25, 2011

Writing Kernel Modules for 2.6



hello.c
1 #include
2 #include
3
4 int init_module(void)
5 {
6 printk(KERN_INFO "Hello world \n");
7 return 0;
8 }
9
10 void cleanup_module(void)
11 {
12 printk(KERN_INFO "Goodbye world \n");
13 }

Makefile
1 obj-m += hello.o
2
3 all:
4 make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
5
6
7 clean:
8 make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
9 fresh: clean all

Commands:

Install Module# insmod hello.ko
Remove Module # rmmod hello.ko
Module info # modinfr hello.ko
List Module # lsmod
Check Log # tail /var/log/messages

Files :
/proc/modules | List of modules |
/proc/kallsyms | List of Symbols |

Sumit..

No comments: