Search

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.

proc_task_pid:



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.


Follow by Email