singsing ~ # cat test.c
#include <stdio.h>
#include <stdlib.h>
#include <pwd.h>
main()
{
struct passwd *pd;
if (NULL == (pd = getpwnam("root")))
perror("getpwnam() error.");
else
{
printf("The user name is: %s\n", pd->pw_name);
printf("The user id is: %u\n", pd->pw_uid);
printf("The group id is: %u\n", pd->pw_gid);
printf("The initial directory is: %s\n", pd->pw_dir);
printf("The initial user program is: %s\n", pd->pw_shell);
}
}
singsing ~ # cc test.c -o test
singsing ~ # ./test
The user name is: root
The user id is: 0
The group id is: 0
The initial directory is: /root
The initial user program is: /bin/bash
singsing ~ #