0

使用 struct task_struct http://lxr.linux.no/linux+v2.6.30.5/include/linux/sched.h#L246中定义的进程如何获取当前用户?我必须检查用户是否是root用户。我显然不能使用 getuid

4

3 回答 3

2

您可以使用task_uid来获取 的用户 ID task_struct,或者task_euid如果这正是您所需要的。

于 2013-02-27T09:35:27.263 回答
0

试试getlogin_r()功能。它在 unistd.h 中定义并返回用户名。看看man getlogin_r其他选项。

int getlogin_r(char *buf, size_t bufsize);
于 2013-02-27T09:40:19.713 回答
0

最终使用了一个成员变量 uid_t uid,我一开始没有看到。检查我使用的 linux 版本(旧)并在这里找到它:http: //lxr.linux.no/linux+v2.6.18/include/linux/sched.h#L246

抱歉,添麻烦了

于 2013-02-27T10:24:47.050 回答