Hi, How do get the current username who is running the current process. I can get the cuurent user ID through getuid(). But how do i get the real name of the user?
i am using gcc 4.1 on ubuntu 7.05 environment.
thank you
ssharish
Hi, How do get the current username who is running the current process. I can get the cuurent user ID through getuid(). But how do i get the real name of the user?
i am using gcc 4.1 on ubuntu 7.05 environment.
thank you
ssharish
Start here. See the "See Also" section.
http://www.opengroup.org/onlinepubs/.../getlogin.html
gg
There is no "real name" of a user, there is just a UID. It's impossible in general to determine the username from the UID, although getlogin() attempts to do so.
For instance, there might be multiple entries in /etc/passwd which all have the same UID. Or, there could be no entry at all for that UID -- that doesn't mean the user doesn't exist, just that it has no username or other associated information.
The username is, of course, useful, but don't design your program around the username as some kind of unique identifier -- only the UID should be used for that.
Also, you should probably use geteuid(), not getuid(), otherwise you will get the wrong username if the process is running as setuid to some other user.