简体   繁体   中英

how to get user of current process

Using the process defined in struct task_struct http://lxr.linux.no/linux+v2.6.30.5/include/linux/sched.h#L246 how do I get the current user? I have to check if the user is root. I apparently can't use getuid

您可以使用task_uid获取task_structtask_euid的用户ID,如果您需要的话。

Try getlogin_r() function. It is defined in unistd.h and returns the username. Have a look at man getlogin_r for other options.

int getlogin_r(char *buf, size_t bufsize);

ended up using a member variable uid_t uid, which I didn't see at first. Checked the version of linux I was using (old) and found it here: http://lxr.linux.no/linux+v2.6.18/include/linux/sched.h#L246

sorry for the trouble

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