who1.c

#include <stdio.h>
#include <utmp.h>
#include <fcntl.h>
#include <unistd.h>

#define SHOWHOST /*include remote machine on output*/

show_info(struct utmp *utbufp)
{
printf("% -8.8s", utbufp->ut_name);//the logname
printf(" ");//a space
printf("% -8.8s", utbufp->ut_line);//the tty
printf(" ");//a space
printf("% -10ld", utbufp->ut_time);//login time
printf(" ");//a space
#ifdef SHOWHOST
printf("(%s)", utbufp->ut_host);//the host
#endif
printf("\n");//newline
}
int main()
{
struct utmp current_record; /*read info into here*/
int utmpfd; /*read from this descriptor*/
int reclen = sizeof(current_record);

if ((utmpfd = open(UTMP_FILE, O_RDONLY)) == -1)
{
perror(UTMP_FILE);/*UTMP_FILE is utmp.h*/
exit(1);
}

while(read(utmpfd, &current_record, reclen) == reclen)
show_info(&current_record);
close(utmpfd);
return 0;/*went ok*/

}

who2.c

#include <stdio.h>
#include <utmp.h>
#include <fcntl.h>
#include <unistd.h>
//who2 added
#include <time.h>

#define SHOWHOST /*include remote machine on output*/

void show_info(struct utmp *utbufp);
//who2 added
void showtime(long);

int main()
{
struct utmp current_record; /*read info into here*/
int utmpfd; /*read from this descriptor*/
int reclen = sizeof(current_record);

if ((utmpfd = open(UTMP_FILE, O_RDONLY)) == -1)
{
perror(UTMP_FILE);/*UTMP_FILE is utmp.h*/
exit(1);
}

while(read(utmpfd, &current_record, reclen) == reclen)
show_info(&current_record);
close(utmpfd);
return 0;/*went ok*/

}

show_info(struct utmp *utbufp)
{
//who2 added
if (utbufp->ut_type != USER_PROCESS)
{
return;
}
//who2 end
printf("% -8.8s", utbufp->ut_name);//the logname
printf(" ");//a space
printf("% -8.8s", utbufp->ut_line);//the tty
printf(" ");//a space
//printf("% -10ld", utbufp->ut_time);//login time
//printf(" ");//a space
showtime(utbufp->ut_time);
#ifdef SHOWHOST
printf("(%s)", utbufp->ut_host);//the host
#endif
printf("\n");//newline
}

//who2 added
void showtime(long timeval)
{
char *cp;//to hold address of time
cp = ctime(&timeval);
printf("%12.12s", cp+4);//pick 12 chars from pos 4
}
//who2 end

who命令的更多相关文章

  1. Cmder--Windows下命令行利器

    cmder cmder是一个增强型命令行工具,不仅可以使用windows下的所有命令,更爽的是可以使用linux的命令,shell命令. 安装包 安装包链接 下载后,直接解压即用. 修改命令提示符λ为 ...

  2. 【每日一linux命令4】常用参数:

     下面所列的是常见的参数(选项)义: --help,-h                              显示帮助信息 --version,-V                        ...

  3. .NET Core系列 : 1、.NET Core 环境搭建和命令行CLI入门

    2016年6月27日.NET Core & ASP.NET Core 1.0在Redhat峰会上正式发布,社区里涌现了很多文章,我也计划写个系列文章,原因是.NET Core的入门门槛相当高, ...

  4. MVVM模式解析和在WPF中的实现(三)命令绑定

    MVVM模式解析和在WPF中的实现(三) 命令绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...

  5. SQLServer执行命令出现“目录无效的提示”

    异常处理汇总-数据库系列  http://www.cnblogs.com/dunitian/p/4522990.html 一般都是清理垃圾清理过头了,把不该删的目录删了 网上说法: 问题描述: 1.s ...

  6. SQLServer文件收缩-图形化+命令

    汇总篇:http://www.cnblogs.com/dunitian/p/4822808.html#tsql 收缩前 图形化演示: 不仅仅可以收缩日记文件,数据库文件也是可以收缩的,只不过日记收缩比 ...

  7. 让 windows 下的命令行程序 cmd.exe 用起来更顺手

    在 Windows 下使用 Larave 框架做开发,从 Composer 到 artisan 总是避免不了和 cmd.exe 打交道,系统默认的命令行界面却是不怎么好看,且每行显示的字符数是做了限制 ...

  8. [版本控制之道] Git 常用的命令总结(欢迎收藏备用)

    坚持每天学习,坚持每天复习,技术永远学不完,自己永远要前进 总结日常开发生产中常用的Git版本控制命令 ------------------------------main-------------- ...

  9. git 命令

    切换仓库地址: git remote set-url origin xxx.git切换分支:git checkout name撤销修改:git checkout -- file删除文件:git rm  ...

  10. svn 常用命令总结

    svn 命令篇 svn pget svn:ignore // 查看忽略项 svn commit -m "提交说明" // 提交修改 svn up(update) // 获取最新版本 ...

随机推荐

  1. 使用python在校内发人人网状态(人人网看状态)_python

    #_*_coding:utf_8_ from sgmllib import SGMLParserimport sys, urllib2, urllib, cookielibimport datetim ...

  2. 优秀的缓存请求库,快速请求接口和图片:WTRequestCenter

    WTRequestCenter 方便缓存的请求库无需任何import和配置,目前实现了基础需求如果有其他需要请在issue 上提出,谢谢! 使用方法 Usage 注意:所有的请求都是缓存的 GET 请 ...

  3. 九度oj 题目1177:查找

    题目描述: 读入一组字符串(待操作的),再读入一个int n记录记下来有几条命令,总共有2中命令:1.翻转  从下标为i的字符开始到i+len-1之间的字符串倒序:2.替换  命中如果第一位为1,用命 ...

  4. chromedriver对应的支持的Chrome版本(更新至Chrome64)

    很多网友在配置chromedriver的时候会遇到很多麻烦,在网上找了很多资料觉得这个表格不错,就给大家分享出来,希望对大家配置chrome的时候有帮助: chromedriver版本 支持的Chro ...

  5. 【hihocoder】欧拉路径 并查集判连通

    #include<iostream> #include<cstdio> #include<string> #include<cstring> #incl ...

  6. 标准C程序设计七---57

    Linux应用             编程深入            语言编程 标准C程序设计七---经典C11程序设计    以下内容为阅读:    <标准C程序设计>(第7版) 作者 ...

  7. Laravel 基础知识

    使用版本Laravel5.1.======================================================目录简单介绍:app目录,核心目录,应用目录.bootstra ...

  8. 转Yii框架radioButtonlist水平横排及去除除换行符号

    横排: echo $form->radiobuttonlist($model, ‘type’,$arrtype,array(‘template’ => ‘<li style=”dis ...

  9. 使用Python计算研究生学分绩(绩点)

    最近看了CSDN上一个专栏<Python爬虫入门教程>,其中最后一篇作者写了个例子,用爬虫计算山东大学绩点,顿时想到前一阵子搞测评的时候还得拿计算器一点点算自己的平均学分绩,也想写一个自己 ...

  10. AC日记——Milking Grid poj 2185

    Milking Grid Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 8314   Accepted: 3586 Desc ...