我需要以某种方式检索真实和有效的 UID 和 GID 以及进程的补充组,而只知道其 PID。
文件fs/proc/array.c
为此目的使用 struct cred
(p 是 struct task_struct *p
):
cred = get_task_cred(p);
但是,我找不到使用另一个进程的 PID 在用户模式下检索此类结构的方法。
有没有办法从用户模式(unix 内核 3.13)获取信息?
最佳答案
有关进程的信息存储在 proc filesystem 中每个进程都有其各自的目录。您要查找的字段是 Uid:
和 Gid:
,它们也包含有效的 UID/GID。
stat Process status
statm Process memory status information
status Process status in human readable form
但是,来自同一个kernel documentation您还可以找到:
Uid Real, effective, saved set, and file system UIDs
Gid Real, effective, saved set, and file system GIDs
由于 proc 文件系统提供的文件 status
只是一个文本文件,您可以继续以任何您喜欢的方式从那里读取所需的信息,例如 fscanf( )
。
关于linux - 从 PID 获取 struct cred,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35246569/