编程实(c++/c)现获得当前用户名和组名的源程序

发表于:2007-07-01来源:作者:点击数: 标签:


#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#include <grp.h>

int main()
{
struct passwd *pwd = getpwuid(getuid());
struct group *grp = getgrgid(getgid());

printf("name: %s group: %s\n", pwd->pw_name, grp->gr_name);
return 0;
}


原文转自:http://www.ltesting.net