Linux下who命令模仿
来源:互联网 发布:centos 桌面图标创建 编辑:程序博客网 时间:2024/05/16 05:13
#include <stdlib.h>#include <stdio.h>#include <unistd.h>#include <utmp.h>#include <fcntl.h>#include <time.h>/* #define SHOWHOST */void showtime(long);void show_info(struct utmp *);int main(){ struct utmp utbuf; /* read info into here */ int utmpfd; /* read from this descriptor */ if ( (utmpfd = open(UTMP_FILE, O_RDONLY)) == -1 ){ perror(UTMP_FILE); exit(1); } while( read(utmpfd, &utbuf, sizeof(utbuf)) == sizeof(utbuf) ) show_info( &utbuf ); close(utmpfd); return 0;}/* * show info() * displays the contents of the utmp struct * in human readable form * * displays nothing if record has no user name */void show_info( struct utmp *utbufp ){ if ( utbufp->ut_type != USER_PROCESS ) return; printf("%-8.8s", utbufp->ut_name); /* 显示用户账号 */ printf(" "); /* 空格 */ printf("%-8.8s", utbufp->ut_line); /*显示端口名 */ printf(" "); /*空格 */ showtime( utbufp->ut_time ); /*显示时间 */#ifdef SHOWHOST if ( utbufp->ut_host[0] != '\0' ) printf(" (%s)", utbufp->ut_host);/* the host */#endif printf("\n"); /* newline */}void showtime( long timeval )/* * displays time in a format fit for human consumption * uses ctime to build a string then picks parts out of it * Note: %12.12s prints a string 12 chars wide and LIMITS * it to 12chars. */{ char *cp; /* to hold address of time */ cp = ctime(&timeval); /* 把时间转化成字符串形式 */ /* string looks like */ /* Mon Feb 4 00:46:40 EST 1991 */ /* 0123456789012345. */ printf("%12.12s", cp+4 ); /* pick 12 chars from pos 4 */}
0 0
- Linux下who命令模仿
- Linux下的w和who命令
- Linux下who命令的实现
- LINUX下tree命令的模仿
- linux who命令
- Linux who 命令
- linux who命令
- Linux who命令
- 初学Linux命令--who
- Linux命令who am i,who,whoami
- Linux下 使用C语言编写who命令
- 【C语言】实现Linux下的who命令
- linux命令之who命令
- 模仿内核缓存之who命令的缓存
- 模仿linux命令ls
- Linux命令详解之who
- linux命令(一) - who
- Linux命令——who
- mysql索引(三)
- LOAD_TYPE_VERSION_MISMATCH与TYPELOAD_NEW_VERSION错误分析
- Find the Difference问题及解法
- [Matlab]结构体(Struct)
- 【敏捷开发每日一贴】债务与缺陷
- Linux下who命令模仿
- keil如何生成bin文件
- SPOJ 19148 INS14G
- C++继承之子类的构造函数
- 重载计算三种类型的绝对值
- 四大组件之 activity
- 单例模式
- 什么是VI?
- Linux使用<一>安装Linux