author: Joseph(Honggang Yang)@dslab // ganggexiongqi@126.com
date: 05-10-2011
Key words: kernel thread, wait queue, /proc/sys/kernel entry, call usermode handler in kernel mode
====================================================
In this section I will show you how to create two kernel threads.
One for process control, the other used to monitor kernel structure.
When kernel structure looks in trouble, the monitor wake up the process kernel thread.
The process kernel thread will call userspace application to handle the error.
In our case, we just print a string to /var/log/messages file.
NOTE : Before doing this experiment, you have to registered /proc/sys/kernel/myevent_handler entry.
ref: http://blog.csdn.net/ganggexiongqi/archive/2011/05/10/6410223.aspx
---------------------------------------------------------------------------------------------------------------------------
1. Code
3. run
# chmod +x helper
#echo /usr/src/linux-2.6.23/joseph/helper > /proc/sys/kernel/myevent_handler // register the usermode helper
# echo "" > /var/log/messages
#insmod test.ko
# cat /var/log/messages
May 11 07:15:31 joseph kernel: [ 4946.127119] Hello, I am a test module
May 11 07:15:31 joseph kernel: [ 4946.127292] Create mythread<---------<<<<<<<<
May 11 07:15:31 joseph kernel: [ 4946.127387] Create monitor <---------<<<<<<
May 11 07:15:31 joseph kernel: [ 4946.127472] monitor out
May 11 07:15:31 joseph kernel: [ 4946.127549] run_umode_handler is starting ...
May 11 07:15:31 joseph kernel: [ 4946.127652] argv[0] is /usr/src/linux-2.6.23/joseph/helper
May 11 07:15:31 joseph kernel: [ 4946.127816] josephThread out
Kernel datastructure 9527 is in trouble
OK, We are success!