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. PHP协程是通过生成器实现的,这里测试了PHP生成器的一些特性

    学习PHP的生成器,测试了一些特性.代码如下: function gen() { $name = (yield 'hello'); $nickname = (yield 'world'); yield ...

  2. iOS学习笔记49-Swift(九)访问控制

    一.Swift的访问控制 Swift中的访问控制模型基于模块和源文件这两个概念 模块指的是Framework或App bundle.在Swift中,可以用import关键字引入自己的工程. 源文件指的 ...

  3. iOS学习笔记48-Swift(八)反射

    一.Swift反射 所谓反射就是可以动态获取类型.成员信息,在运行时可以调用方法.属性等行为的特性. 在使用OC开发时很少强调其反射概念,因为OC的Runtime要比其他语言中的反射强大的多.不过在S ...

  4. 【Luogu】P2596书架(Splay)

    题目链接 通过这题我加深了对Splay的理解,原来Splay的子树也是可以接来接去接到别的点上的,而不是只能旋转qwq 具体接的办法就是swap大法. 对于Top操作我们把当前节点Splay到根,然后 ...

  5. pycharm提示your evalluation license has expired解决方法

    安装pycharm,一段时间后提示your evalluation license has expired:打开pycharm--点击help--register--选中license server, ...

  6. 浅谈HookSSDT和和Resume(恢复)SSDT

     最近在学HookSSDT和针对Hook的ResumeSSDT,避免自己理解有所偏差,把它们写出来,希望大家不吝赐教.(虽然已经是过时了的技术,但是最起码了解其中的原理,嘿嘿嘿.) 转载注明出处:ht ...

  7. 微信小程序踩坑之一[wx.request]请求模式

    最近在做小程序时,使用wx.request()方法请求时, 当使传输string类型时,一定要声明method请求模式为post,否则会一直报错,而不声明时默认为get, 已填坑 =,= wx.req ...

  8. Pollard_rho定理 大数的因数个数 这个板子超级快

    https://nanti.jisuanke.com/t/A1413 AC代码 #include <cstdio> #include <cstring> #include &l ...

  9. 洛谷——P2296 寻找道路

    P2296 寻找道路 题目描述 在有向图G 中,每条边的长度均为1 ,现给定起点和终点,请你在图中找一条从起点到终点的路径,该路径满足以下条件: 1 .路径上的所有点的出边所指向的点都直接或间接与终点 ...

  10. Nginx三种模式的虚拟主机(附Apache基于域名的虚拟主机)

    1.安装nginx # pcre中文"perl兼容正则表达式",安装pcre库是为了让nginx支持具备URL重写功能 # 的Rewrite模块,rewrite可以实现动态页面转成 ...