author: joseph
email: ganggexiongqi@gmail.com
==============================
本节介绍下kernel thread简单使用的例子实验.
我的系统:
joseph:/usr/src/linux-2.6.23/joseph# uname -a
Linux joseph 2.6.23 #1 SMP PREEMPT Fri May 6 18:02:45 CST 2011 i686 GNU/Linux
文件:
├── hello.c
└── Makefile
1. hello.c
2. Makefile
obj-m := hello.o
3. 编译
#make -C /usr/src/linux-2.6.23 M=`pwd` modules
// /usr/src/linux-2.6.23 是我的源码路径
会生成 hello.ko
4. 清除记录的信息
#
echo "" > /var/log/messages
5. 插入模块
# insmod hello.ko
6. 查看信息
# cat /var/log/messages
May 7 20:24:10 joseph kernel: [ 4281.427586] Hello, I am a test module
May 7 20:24:10 joseph kernel: [ 4281.427758] Create mythread<---------<<<<<<<<
查看我们的内核线程
#ps -ef
...
root 4030 2 0 20:24 ? 00:00:00 [josephThread]
...
7. 结束内核线程
#kill -s 9 4030
查看信息
# cat /var/log/messages
May 7 20:24:10 joseph kernel: [ 4281.427586] Hello, I am a test module
May 7 20:24:10 joseph kernel: [ 4281.427758] Create mythread<---------<<<<<<<<
May 7 20:27:22 joseph kernel: [ 4472.245694] josephThread out <------<<<<<
8. 卸载模块
#rmmod hello
查看信息
#cat /var/log/messages
May 7 20:24:10 joseph kernel: [ 4281.427586] Hello, I am a test module
May 7 20:24:10 joseph kernel: [ 4281.427758] Create mythread<---------<<<<<<<<
May 7 20:27:22 joseph kernel: [ 4472.245694] josephThread out <------<<<<<
May 7 20:28:43 joseph kernel: [ 4553.589958] Bye, my dear!
May 7 20:28:43 joseph kernel: [ 4553.589960] Cruel world