I am trying to find the virtual file that contains the current users id. I was told that I could find it in the proc directory, but not quite sure which file.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You actually want
/proc/self/status, which will give you information about the currently executed process.Here is an example:
You probably want to look at the first numbers on the Uid and Gid lines. You can look up which uid numbers map to what username by looking at
/etc/passwd, or calling the relevant functions for mapping uid to username in whatever language you’re using.Ideally, you would just call the system call
getuid()to look up this information, doing it by looking at/proc/is counterproductive.