I am new to kernel module progrmming. In my program I need to display the process name and its parent's pid.
The following is my simple_init() function
int simple_init(void){
printk(KERN_INFO "--------------Starting module--------------\n");
struct task_struct *intask = &init_task;
struct list_head fd = intask->children;
struct list_head *list;
struct task_struct *task;
int k =0;
list_for_each(list, &fd){
task = list_entry(list, struct task_struct, sibling);
struct task_struct *parent = task->parent;
pid_t parent_pid = parent -> pid;
printk(KERN_INFO "Name: %s ---- %d ----Parent: %d\n",task->comm, task->pid, parent_pid);
if (k==2) break;
k++;
}
return 0;
}
Problem is that after I added the line:
struct task_struct *parent = task->parent;
Now, when I run the insmod command it says Segementation fault, and I have to restart the machine (virtual machine) to try again.
Can anyone of you show me what's wrong with this?
progrmming
from your post, you would also have one typo less. – Anthonintask->children
is what?list
is what?task
is what?task->parent
is what? – Zan Lynx