-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlist_proc.c
39 lines (31 loc) · 889 Bytes
/
list_proc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
/* TODO: add missing headers */
#include <linux/sched.h>
#include <linux/sched/signal.h>
MODULE_DESCRIPTION("List current processes");
MODULE_AUTHOR("Kernel Hacker");
MODULE_LICENSE("GPL");
static int my_proc_init(void)
{
struct task_struct *p;
/* TODO: print current process pid and its name */
pr_err("current Process PID = %d, comm = %s\n", current->pid,
current->comm);
/* TODO: print the pid and name of all processes */
pr_info("____________________________________\n");
for_each_process(p) {
pr_err("Process PID = %d, comm = %s\n", p->pid,
p->comm);
}
return 0;
}
static void my_proc_exit(void)
{
/* TODO: print current process pid and name */
pr_err("current Process PID = %d, comm = %s\n", current->pid,
current->comm);
}
module_init(my_proc_init);
module_exit(my_proc_exit);