Getting a user ID and a process group ID from a task_struct and a pid_namespace

时间:2015-10-30 22:30:22

标签: process linux-kernel userid process-group

I'm trying to modify Linux kernel and I need to get the user ID and the process group ID from a task_struct and a pid_namespace. Although I searched their definitions in the source code, I couldn't find any global variables or functions (maybe I am missing because of the lack of the comments in codes) to access them.

Is there a method to get those inside the kernel space since I can not use user-space functions like getuid(), etc.?

1 个答案:

答案 0 :(得分:6)

You should be able to use task_struct->cred->uid or task_struct->real_cred->uid. That being said, I have not tested this and this is just from a cursory reading of LXR (include/linux/sched.h line 1508 and include/linux/cred.h line 127).

If you want the PGID, try pid_vnr(task_pgrp(task_struct)). This code is from kernel/sys.c line 990.