CS433 Linux Kernel Programming Homework
Homework 2 on
Kernel Module Programming
Submission:Prepare a tgz (tar gzip) file containing the source code file(s) you created/modified and screen shots that show that your program executed properly. Upload the file to the class homework submission site found on the homework page.
Write three simple and small module programs.
The Linux Kernel Module Programming Guide has all the details. However, you should do the homework yourself.
- Insert a module using "/sbin/insmod hello{1..3}.ko." Note that the dot after ko is not meant to be a part of the command (it's part of the sentence). Each time you insert it will print whatever you included in the module will be printed to console or /var/log/messages. For example, if you defined the module init function as:
static int hello1_init(void){
printk(KERN_INFO "My Name: Loading Hello2 module - Hello World.\n");
return 0;
}
You will see in /var/log/messages "My Name: Loading Hello2 module - Hello World.\n" Use "tail /var/log/messages" to check the message.
- List all the modules using "/sbin/lsmod" to see if the one you just inserted is there.
- Remove a module using "/sbin/rmmod hello{1..3}"
If you defined the module exit function as:
static int hello1_exit(void){
printk(KERN_INFO "My Name: Exiting Hello2 module - Goodbye World.\n");
}
You will see in /var/log/messages "My Name: Exiting Hello2 module - Goodbye World.\n" Again, use "tail /var/log/messages" to verify that the module has indeed been removed.
Here are the three modules you will implement in this homework:
- hello1.c: Use module_init() and module_exit() macros. The /var/log/message file will show
"My Name: Loading Hello1 module - Hello World 1"
"My Name: Exiting Hello1 module - Goodbye World 1"
- hello2.c: Use module_init(), module_exit(), __init, __exit macros, and __initdata. The /var/log/message file will show
"My Name: Loading Hello2 module - Hello World 2"
"My Name: Exiting Hello2 module - Goodbye World 2"
Print the number "2" using "__initdata."
- hello3.c: passing command line arguments using MODULE_PARM() macro.
Try to print some numbers and strings such as
[/var/log/messages]
...
#kernel: Loading Hello 3: Hello World 3
#kernel: ==============================
#kernel: Name : My Name
#kernel: Street : 123 My Way
#kernel: City : North Newark
#kernel: ZIP code : 98765
Again, the web page is for your reference. Do the homework yourself.