Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #include<linux/module.h>
  2. #include<linux/sched.h>
  3.  
  4. static int __init init_tasklist(void)
  5. {
  6. struct task_struct *p;
  7.  
  8. for_each_process(p) {
  9. printk(KERN_INFO "Process name is: %s, and its pid is: %i. ",p->comm, p->pid);
  10. if(p->state==TASK_RUNNING)
  11. printk("Process state is TASK_RUNNING\n");
  12. if(p->state==TASK_INTERRUPTIBLE)
  13. printk("Process state is TASK_INTERRUPTIBLE\n");
  14. if(p->state==TASK_UNINTERRUPTIBLE)
  15. printk("Process state is TASK_UNINTERRUPTIBLE\n");
  16. if(p->state==TASK_STOPPED)
  17. printk("Proces state is TASK_STOPPED\n");
  18. }
  19. return 0;
  20. }
  21.  
  22. static void __exit exit_tasklist(void) {
  23.  
  24. struct task_struct *p;
  25.  
  26. for_each_process(p) {
  27. printk(KERN_INFO "Process name is: %s, and its pid is: %i. ",p->comm, p->pid);
  28. if(p->state==TASK_RUNNING)
  29. printk("Process state is TASK_RUNNING.\n");
  30. if(p->state==TASK_INTERRUPTIBLE)
  31. printk("Process state is TASK_INTERRUPTIBLE.\n");
  32. if(p->state==TASK_UNINTERRUPTIBLE)
  33. printk("Process state is TASK_UNINTERRUPTIBLE.\n");
  34. if(p->state==TASK_STOPPED)
  35. printk("Proces state is TASK_STOPPED.\n");
  36. }
  37. }
  38.  
  39. module_init(init_tasklist);
  40. module_exit(exit_tasklist);
  41.  
  42. MODULE_LICENSE("GPL");
  43. MODULE_DESCRIPTION("Simple module that prints name, pid and state of every running process.");
  44. MODULE_AUTHOR("Arkadiusz Chrobot <a.chrobot@tu.kielce.pl>");
  45. MODULE_VERSION("1.0");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement