|
|
源代码如下:
#include <stdio.h>
#include <utmp.h>
#include <fcntl.h>
#include <unistd.h>
#define SHOWHOST
void show_info(struct utmp *utbufp);
int main()
{
struct utmp current_record;
int utmpfd;
int reclen=sizeof(current_record);
if((utmpfd=open(UTMP_FILE,O_RDONLY))==-1){
perror(UTMP_FILE);
exit(1);
}
while(read(utmpfd,¤t_record,reclen)==reclen)
show_info(¤t_record);
close(utmpfd);
return 0;
}
void show_info(struct utmp *utbufp)
{
printf("%-8.8s",utbufp->ut_name);
printf(" ");
printf("%-8.8s",utbufp->ut_line);
printf(" ");
printf("%-8.8s",utbufp->ut_time);
printf(" ");
#ifdef SHOWHOST
printf("(%s)",utbufp->ut_host);
#endif
printf("\n");
}
gcc的调试结果是这样的:
Segmentation fault
请问各位可有知道这是什么原因造成的
我的系统是RedHat 9.0
用的gcc是系统自带的版本
在此谢谢了 |
|