从内核级代码的pid(进程ID)获取uid [英] get uid from pid(process id) from kernel level code

查看:115
本文介绍了从内核级代码的pid(进程ID)获取uid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取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

推荐答案

  1. 使用给定的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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆