简体   繁体   中英

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)?

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() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM