Reputation: 195
I would like to retrieve caller process' PID (Userspace) in Linux Driver.
At first, I could find pid
attribute so easy from the struct task_struct
in Linux Source Code (include/linux/sched.h
) I used current->pid
to retrieve userspace PID.
However, I read some articles telling that the pid
in Kernel and Userspace context are different. In other words, so called userspace PID is in fact tgid
which is also an attribute of struct task_struct
.
Moreover, when I look into the source code getpid()
system call expecting this should return task_struct.pid
or task_struct.tgid
, it turns out that it returned unexpected function- task_tgid_vnr
- ultimately uses the signal
inside task_struct
.
As my ultimate goal was so simple- to find out the exact same PID retrieved from getpid()
system call in Linux kernel- I am very confused.
In conclusion, among all the options above, which way is the recommended way to retrieve the caller process' userspace PID?
Upvotes: 0
Views: 30