列出所有进程

 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);
View Code

相关文章:

  • 2021-11-24
  • 2022-01-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2022-03-09
  • 2021-08-04
猜你喜欢
  • 2021-08-10
  • 2021-11-13
  • 2022-12-23
  • 2022-02-19
  • 2022-12-23
  • 2021-12-09
相关资源
相似解决方案