I want to write a kernel module that inspects the scheduled instructions of a running process. I already had a look at Linux Kernel Process Management, which explains how to iterate over processes.
struct task_struct *task;
for_each_process(task) {
/* this pointlessly prints the name and PID of each task */
printk("%s[%d]\n", task->comm, task->pid);
}
But once I get hold of a task_struct
, how can I get to the instructions? I am assuming that I need to find the program-counter first, to see which instructions are about to be executed next.
Which member of the task_struct
do I need to inspect to end up at the instructions? And in what kind of struct
type are they stored?
Thanks for your help. I'm not that experienced with kernel programming.