Getting uid and/or username of logged in user
Hi
I am writing a C++ app and i need a way to get the the user ID and the user name of the currently logged in user. Any ideas? (BTW, this is on linux) |
man utmp ;)
|
thanks.
|
If you mean that you want the username and ID of the user who is running the program, you can use
Code:
#include <unistd.h> Code:
#include <pwd.h> You can also get the username of the current user (which may or may not be either the logged in user or the user running the process; see su -m) using Code:
#include <stdlib.h> — Robert J. Lee |
thankyou rjiee, I am using:
Code:
#include <unistd.h> Cedrik, thanks but I was just searching on google for details of how to get that to work. Couldn't find any, then I saw rjiee suggestion. Thanks anyway. |
void is only allowed in function prototypes in C or C++. It just means that no parameter is allowed (and can sometimes be omitted).
|
All times are GMT -5. The time now is 08:15 PM. |