Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Efficient way to find task_struct by pid

Is there an efficient way of finding the task_struct for a specified PID, without iterating through the task_struct list?

like image 649
zer0stimulus Avatar asked Dec 17 '11 19:12

zer0stimulus


People also ask

What is struct pid?

* A struct pid is the kernel's internal notion of a process identifier. * It refers to individual tasks, process groups, and sessions. While. * there are processes attached to it the struct pid lives in a hash. * table, so it and then the processes that it refers to can be found.

What is task_struct?

The task_struct is a relatively large data structure, at around 1.7 kilobytes on a 32-bit machine. This size, however, is quite small considering that the structure contains all the information that the kernel has and needs about a process.

Where is task_struct stored?

From the perspective of Virtual memory system, task_struct is allocated by the Slab allocator, so that it's located in the kernel space.


1 Answers

What's wrong with using one of the following?

extern struct task_struct *find_task_by_vpid(pid_t nr);
extern struct task_struct *find_task_by_pid_ns(pid_t nr,
            struct pid_namespace *ns);
like image 160
jørgensen Avatar answered Oct 19 '22 09:10

jørgensen