linux - 从 PID 获取 struct cred

标签 linux security process permissions credentials

我需要以某种方式检索真实和有效的 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。

来自kernel documentation :

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/

相关文章:

java - 弹力城堡 DefaultSignatureAlgorithmIdentifierFinder NoSuchFieldError : gostR3410_94

linux内核,task_struct(进程)初始化在哪里

C++游戏训练器进程监控

linux - 如何根据模式将一个文件拆分为两个文件?

linux - 如何将/dev/sda 与/dev/sdb 交换?

c - 不显示 SDL 的 OpenGL 窗口

linux - 如何使用 Shell 查找区间内的平均值和最大值

c# - 清理发往电子邮件的用户输入

database - 保护数据库和网页不被修改

android:进程和进程名称