//process.c
#include<linux/kernel.h> #include <linux/init.h> #include <linux/module.h>
static int __init process_init(void) { int result = 0; struct task_struct *p; read_lock(&tasklist_lock);//锁 for_each_process(p) { printk("pid=%d,name=%s\n",p->tgid,p->comm); } read_unlock(&tasklist_lock); return result; }
static void __exit process_exit(void) { printk("process_exit"); }
module_init(process_init); module_exit(process_exit);
MODULE_LICENSE("GPL");
|
Makefile和上一篇差不多~
加载模块查看dmesg如下:
pid=1,name=init
pid=2,name=ksoftirqd/0
pid=3,name=watchdog/0
pid=4,name=events/0
pid=5,name=khelper
pid=6,name=kthread
pid=8,name=kacpid
pid=68,name=kblockd/0
pid=117,name=pdflush
pid=118,name=pdflush
pid=120,name=aio/0
pid=71,name=khubd
转:http://blog.chinaunix.net/u/18520/showart_384279.html
阅读(1311) | 评论(0) | 转发(0) |