I have this chunk of code for a linux kernel module:
#include <linux/module.h> #include <linux/kernel.h> #include <linux/sched.h> #include <linux/init_task.h>#include <linux/list.h>struct task_struct *initTask = &init_task;struct task_struct *type;int init_module(void){ int process_count = 0; printk("Hello, Jared Rathbun\n"); /* Print the init process */ printk("Init Process\n"); printk(KERN_INFO "Name: %-20s| PID: %-5d| State: %-5ld| Priority: %-5d| Policy: %-5d| Recent CPU: %-5d| Parent Name: %-20s| PPID: %-5d\n", initTask->comm, initTask->pid, initTask->state, initTask->prio, initTask->policy, initTask->recent_used_cpu, initTask->parent->comm, initTask->parent->pid); static LIST_HEAD(task_list_head); /* Traverse the Linked List of processes */ list_for_each_entry(type, &task_list_head, tasks) { printk("inside loop"); process_count++; printk(KERN_INFO "Name: %-20s| PID: %-5d| State: %-4ld| Priority: %-5d| Policy: %-5d| Recent CPU: %-5d| Parent Name: %-20s| PPID: %-5d\n", type->comm, type->pid, type->state, type->prio, type->policy, type->recent_used_cpu, type->parent->comm, type->parent->pid); } /* Print the current process */ printk("Current Process\n"); printk(KERN_INFO "Name: %-20s| PID: %-5d| State: %-5ld| Priority: %-5d| Policy: %-5d| Recent CPU: %-5d| Parent Name: %-20s| PPID: %-5d\n", current->comm, current->pid, current->state, current->prio, current->policy, current->recent_used_cpu, current->parent->comm, current->parent->pid); printk(KERN_INFO "TOTAL PROCESS COUNT: %d\n", process_count); return 0;}void cleanup_module( void ){ return;}MODULE_LICENSE("GPL");MODULE_DESCRIPTION("Kernel Module that traverse the list of running processes on the OS");MODULE_AUTHOR("JR");
When I insert this using insmod, the kernel does not execute these lines of code, as if it just skips it like a condition isn't true. Has anyone seen this before?
Thanks in advance!