Home Ask Login Register

Developers Planet

Your answer is one click away!

just.me February 2016

Get struct cred from PID

I need to somehow retrieve both real and effective UID and GID as well as the supplementary groups of a process, knowing only its PID.

The file fs/proc/array.c uses the struct cred for that purpose (p is struct task_struct *p):

cred = get_task_cred(p);

However, I cannot find a way to retrieve such a struct in user-mode using the PID of another process.

Is there any way to get the information from user-mode (unix kernel 3.13)?


Sami Laine February 2016

Information about processes is stored in proc filesystem where each process has its respective directory. The fields you're looking for are Uid: and Gid: which also contain effective UID/GID.

From the kernel documentation:

stat        Process status
statm       Process memory status information
status      Process status in human readable form

However, from the same kernel documentation you can also find:

Uid                         Real, effective, saved set, and  file system UIDs
Gid                         Real, effective, saved set, and  file system GIDs

Since the file status served from the proc filesystem is simply a text file, you can just go ahead and read the required information from there with any way you like, for example fscanf().

Post Status

Asked in February 2016
Viewed 1,356 times
Voted 8
Answered 1 times


Leave an answer

Quote of the day: live life