23,125
社区成员
发帖
与我相关
我的任务
分享
root
user name is root
user dir is /root
[root@localhost test]# cat getlogin.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
int main(int argc,char* argv[])
{
char * login = getlogin();
printf("%s\n",login);
struct passwd *ps = getpwnam(login);
printf("user name is %s\n",ps->pw_name);
printf("user dir is %s \n",ps->pw_dir);
return 0;
return 0;
}