问题描述
我想获取pid的uid.请注意,我要获取的uid不在当前进程中.如果您有任何想法,请告诉我.也许可以通过重用内核中的/proc/[pid]/status read函数来获取它?//布鲁斯
I would like to get uid of a pid. Please note that the uid that I want to get is NOT of the current process.Please let me know if you have an idea.Maybe can I get it by reuse the function of /proc/[pid]/status read function in kernel?//Bruce
推荐答案
-
使用给定的pid搜索进程描述符(
struct task_struct
).
使用 task-> cred-> uid
.
结构 struct task_struct
在 include/linux/sched.h
中定义.结构 struct cred
在 include/linux/cred.h
中定义.
Struct struct task_struct
is defined in include/linux/sched.h
. Struct struct cred
is defined in include/linux/cred.h
.
请注意,应在RCU关键部分下遍历流程和读取流程的凭据.
Note, that iterating through processes and reading process's credentials should be done under RCU-critical section.
这篇关于从内核级代码的pid(进程ID)获取uid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!