📄 who.txt
字号:
/*who.c*/
2 #include <stdio.h>
3 #include <utmp.h>
4 #include <unistd.h>
5 #include <fcntl.h>
6 #include <time.h>
7
8 #define SHOWHOST
9 void show_info(struct utmp *);
10 void showtime(long timeval);
11 int main()
12 {
13 struct utmp current_record;
14 int utmpfd;
15 int reclen=sizeof(current_record);
16
17 if((utmpfd=open(UTMP_FILE,O_RDONLY))==-1)
18 {
19 perror(UTMP_FILE);
20 exit(1);
21 }
22
23 while(read(utmpfd,¤t_record,reclen)==reclen)
24 show_info(¤t_record);
25 close(utmpfd);
26 return 0;
27 }
28
29 void show_info(struct utmp *utbufp)
{
31 //see difinitions for ut_type,只显示注册登陆用户
32 if(utbufp->ut_type!=USER_PROCESS)
33 return;
34 printf("%-8s",utbufp->ut_name);
35 printf(" ");
36 printf("%-8s",utbufp->ut_line);
37 printf(" ");
38 showtime(utbufp->ut_time);
39
40 #ifdef SHOWHOST
41 printf("(%s)",utbufp->ut_host);
42 #endif
43 printf("\n");
44 }
45
46 void showtime(long timeval)
47 {
48 char *cp;
49 cp=ctime(&timeval);
50 printf("%12.12s",cp+4);//show from the fourth char
51 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -