Created
March 29, 2016 20:32
-
-
Save anryko/c8c8788ccf7d553a140a03aba22cab88 to your computer and use it in GitHub Desktop.
Simple kernel module example. Lists process list and count.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <linux/module.h> // Needed by all modules | |
#include <linux/kernel.h> // KERN_INFO | |
#include <linux/sched.h> // for_each_process, pr_info | |
void procs_info_print(void) | |
{ | |
struct task_struct* task_list; | |
size_t process_counter = 0; | |
for_each_process(task_list) { | |
pr_info("== %s [%d]\n", task_list->comm, task_list->pid); | |
++process_counter; | |
} | |
printk(KERN_INFO "== Number of process: %zu\n", process_counter); | |
} | |
int init_module(void) | |
{ | |
printk(KERN_INFO "[ INIT ==\n"); | |
procs_info_print(); | |
return 0; | |
} | |
void cleanup_module(void) | |
{ | |
printk(KERN_INFO "== CLEANUP ]\n"); | |
} | |
MODULE_LICENSE("MIT"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
obj-m += lkm_hello1.o | |
KDIR ?= /lib/modules/$(shell uname -r)/build | |
all: | |
make -C $(KDIR) M=$(PWD) modules | |
clean: | |
make -C $(KDIR) M=$(PWD) clean |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment