编写who命令
来源:互联网 发布:chairgun3弹道软件 编辑:程序博客网 时间:2024/05/31 18:47
Refer:编写who命令
#include<stdio.h>#include<utmp.h>#include<string.h>#include<stdlib.h>#include<time.h>#define SHOWHOSTvoid show_info(struct utmp*);int main(){ struct utmp record; FILE *fp; int strulen=sizeof(record); if((fp=fopen("/var/run/utmp","r"))==0){ //打开文件 perror("fopen"); exit(0); } memset(&record,0x00,strulen); while(fread(&record,strulen,1,fp)){ //循环读取记录(结构体) show_info(&record); } fclose(fp); //关闭文件 return 0;}void show_info(struct utmp *buf){ if(buf->ut_type!=USER_PROCESS) //非登录用户 return; printf("%-8s ",buf->ut_name); //输出用户名 printf("%-12s ",buf->ut_line); //终端设备名 time_t timelong=buf->ut_time; struct tm *localnow=localtime(&timelong); printf("%04d-%02d-%02d %02d:%02d ",localnow->tm_year+1900,localnow->tm_mon+1,localnow->tm_mday,localnow->tm_hour,localnow->tm_min); //登录时间 #ifdef SHOWHOST printf("(%s)",buf->ut_host); #endif printf("\n");}
0 0
- 自己编写who命令
- who命令的编写
- 编写who命令
- 编写who命令
- 编写自己的who命令
- 自己用C语言编写who命令
- Linux_自己编写一个who命令
- linux编程—who命令编写
- Shell命令编写——查看当前用户who
- Linux下 使用C语言编写who命令
- 编写who命令--从Linux中学习Linux
- 【Unix/Linux编程实践】从零做起:编写who命令
- who命令
- who命令
- who命令的编写——登录与注销__who, whoami, who am i
- 编写who命
- 自己动手编写一个简单的who命令(不带参数)
- 自己动手编写一个简单的who命令(不带参数)
- Syntax error, parameterized types are only available if source level is 1.5
- Log4J--日志第一发
- JAVA技术总结
- 黑马程序员——— 银行业务调度系统
- TCP 的那些事儿(上)
- 编写who命令
- topcoder-srm610-div2-1000(dp)
- 【css实践】全屏实现背景图片
- Perl 采集监控日志插入数据库
- Lua脚本语法说明(修订)
- 去掉重复的文件
- 黑马程序员_Java语言_异常,File类
- 剑指Offer之 - 字符串的排列
- TCP 的那些事儿(下)