诊断 DB2 Java 应用程序的性能问题 (2)
2008-09-16 16:29:15 来源:WEB开发网清单 33. 调用操作系统认证 API 的示例程序
#include <stdio.h>
#include <sys/types.h>
#include <pwd.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
int err = 0;
int rc = 0;
struct passwd *pResult = NULL;
struct passwd passwordData;
char *pBuffer = (char *)malloc(256);
if (argc != 2)
{
printf("Usage: %s <userid> n", argv[0]);
exit (1);
}
pResult = getpwnam(argv[1]);
if (pResult == NULL)
{
err = errno;
printf("n1: err: %d", err);
}
else
{
printf("getpwnam returned OK. n");
}
rc = getpwnam_r(argv[1],
&passwordData,
pBuffer,
256,
&pResult);
if ((rc != 0) || (pResult == NULL))
{
err = errno;
printf("n2: err: %d, rc: %dn", err, rc);
}
else
{
printf("getpwnam_r returned OK. n");
}
}
将以上代码保存为 testgetpwnam.C,并编译该代码,生成可执行文件 a.out。下面的命令运行程序 a.out,该程序查找用户 bianca,并将实际时间、用户时间和系统时间写到标准错误。
更多精彩
赞助商链接