按照unix-linux编程实践教程的代码敲了一遍,发现mac中没有utmp文件而是用utmpx文件后就去查看了utmpx.h看登陆信息的结构(utmpx.h)
程序运行成功,但是访问出来的信息却和who命令又很大不同甚至可以说没有,难道mac是是用其他文件来保存登陆信息的吗?还请高手们支个招:
下面是代码:
void show_info(struct utmpx *utbufp)
{
void show_time();
// if (utbufp->ut_type != USER_PROCESS)
// return;
printf("%-8.8s", utbufp->ut_user); /* the logname*/
printf(" ");
printf("%-8.8s", utbufp->ut_line); /* the tty */
printf(" ");
show_time();
ifdef SHOWHOST
if (utbufp->ut_host[0] != '\0')
printf("(%s)", utbufp->ut_host); /* the host */
endif
printf("\n");
}
输出是这样的: