Untitled
unknown
plain_text
2 years ago
1.6 kB
1
Indexable
Never
#include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/sched/signal.h> #include <linux/sched.h> #define GREEN(x) "\x1b[92m" x "\x1b[0m" #define BLUE(x) "\x1b[96m" x "\x1b[0m" #define UNDERLINE(x) "\x1b[4m" x "\x1b[0m" MODULE_LICENSE("GPL"); MODULE_AUTHOR("PES1"); MODULE_DESCRIPTION("Process list program"); MODULE_VERSION("1.0"); static int __init process_print (void) { struct task_struct *task; struct task_struct *task_child; struct list_head *list; int count = 10; printk("%s", GREEN("Loading kernel module\n")); printk("%s\t%s\t%s\t%s\t\n", BLUE(UNDERLINE("PPNAME")), BLUE(UNDERLINE("PPID")), BLUE(UNDERLINE("PNAME")), BLUE(UNDERLINE("PID"))); for_each_process(task) { list_for_each(list, &task->children) { task_child = list_entry(list, struct task_struct, sibling); printk("%s\t%d\t%s\t%d\t\n", task->comm, task->pid, task_child->comm, task_child->pid); --count; if (count <= 0) return 0; } } return 0; } static void __exit cleanup (void) { printk(KERN_INFO "Exiting\n"); Makefile run.sh Output } module_init(process_print); module_exit(cleanup); /* /////////////////////////////////////////////////////////////////////////////////////////////////////// obj-m += main.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean /////////////////////////////////////////////////////////////////////////////////////////////////////// sudo insmod main.ko sudo modinfo main.ko tail /var/log/kern.log -n 12 sudo rmmod main.ko */