列出所有进程
1 #include <linux/kernel.h> 2 #include <linux/module.h> 3 #include <linux/init.h> 4 #include <linux/sched.h> 5 #include <linux/list.h> 6 7 static __init int print_pid(void) 8 { 9 struct task_struct *task,*p; 10 struct list_head *pos; 11 int count=0; 12 printk("Hello,let begin\n"); 13 task = &init_task; 14 list_for_each(pos,&task->tasks) 15 { 16 p = list_entry(pos, struct task_struct, tasks); 17 count++; 18 printk("%d---->%s-->%X\n",p->pid,p->comm, p->state); 19 } 20 printk("the number of process is:%d\n",count); 21 return 0; 22 } 23 24 static __exit void print_exit(void) 25 { 26 printk("<0>end!\n"); 27 } 28 module_init(print_pid); 29 module_exit(print_exit);
时间: 2024-11-05 09:25:12