Module to find a task from its pid

Here is a module which find the task_struct of a process from its pid. To find the task_struct of a process we can make use of the function pid_task defined in kernel/pid.c .

Arguments :

To find the pid structure if we have the pid of a process we can use the functionfind_get_pid which is also defined in kernel/pid.c

In the below module we create a read/write proc entry named task_by_pid. Which ever process we want to find the task_struct of using its pid we can write to number into the proc entry.

When we read the proc entry, it will display the name of the process corresponding to the pid we wrote into it.


Use the following make file to compile it:

Insert it into the kernel

Now let us try to find the name of the process with pid "1", which is always init.

As expected the output is "init". Thus we can find the task_struct of any process using its pid.

1 comment:

  1. can you help me to make a system call that print the whole task_struct corresponding to a process ?


Follow by Email