With experience in system calling, it is still very smooth to add modules.
[Lab environment]
Fedora, kernel 2.6.21.6
Lab procedure]
1. CD/root/homework/Module
2. VI process. c
3. Add the following code:
# Include <Linux/kernel. h> <br/> # include <Linux/init. h> <br/> # include <Linux/module. h> <br/> static int process_init (void) <br/> {<br/> int num = 0; <br/> struct task_struct * P; <br/> for_each_process (p) <br/>{< br/> struct task_struct * q = p-> parent; <br/> printk ("pid = %-5d, name = %-20 s, ", p-> tgid, p-> comm); <br/> printk (" PRIO = %-5d ,", p-> PRIO); <br/> printk ("my_parent is: % s [% d]/n", Q-> comm, Q-> tgid ); <br/> nu M ++; <br/>}< br/> printk ("/ntotal number is: % d/N", num); <br/> return num; <br/>}</P> <p> static void process_exit (void) <br/> {<br/> printk ("=======================/N "); <br/> printk ("process_exit, goodbye! /N "); <br/>}</P> <p> module_init (process_init); <br/> module_exit (process_exit ); <br/> module_license ("GPL"); <br/>
4. VI makefile
5. Add the following code:
OBJ-M: = process. o
ALL:
Make-C/lib/modules/$ (shell uname-R)/build M = $ (shell PWD) Modules
Clean:
Make-C/lib/modules/$ (shell uname-R)/build M = $ (shell PWD) clean
6. Make
7./sbin/init 3 enter the character Interface
8. insmod process. Ko Display Results
9. rmmod process. Ko is removed from the kernel and the result is displayed.