kernel thread, wait queue, /proc/sys/kernel entry, call usermode handler in kernel mode

 

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!

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值