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. HDU-2413 Against Mammoths

    二分答案,对于当前答案Ans,求出某些人类可打败某些外星人的对应边,建图后求是否有完备匹配. //#include <cmath> #include <cstdlib> #in ...

  2. 如何在Windows上卸载DB2

    怎么在Windows下正确卸载DB2: http://www.360doc.com/content/11/1117/16/7485728_165237689.shtml ↑↑↑ 上面的文章挺复杂,我没 ...

  3. C#递归删除进程及其子进程

    /// <summary> /// 结束进程和相关的子进程 /// </summary> /// <param name="pid">需要结束的 ...

  4. jacoco功能测试覆盖率统计

    1.在java程序的启动脚本(或者tomcat)中加入javaagent参数-javaagent:/home/apps/jacocoagent.jar=destfile=/home/apps/jaco ...

  5. javascript之进阶

    一 模态框 1 什么是模态框 模态框(Modal)是覆盖在父窗体上的子窗体.指在用户想要对对话框以外的应用程序进行操作时,必须首先对该对话框进行响应.如单击[确定]或[取消]按钮等将该对话框关闭. 2 ...

  6. 在vue路由当中使用keep-alive避免多次加载组件,减少消耗

    今天在vue当中使用了full-page这个组件.但是发现在每次路由跳转完之后,再回到使用fullpage的这个页面,fullpage会报错,fullpage只能初始化一次. 这个时候给路由使用kee ...

  7. storage存储对象和数组类型时候的问题

    storage类型存储的类型为字符串,直接使用localstorage.setItem方法存储进去,取出来的时候数据是不能够使用的 解决方法: 先使用JSON.stringify方法转换成为字符串,然 ...

  8. 标准C程序设计七---114

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

  9. 标准C程序设计七---35

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

  10. 打印倒序NxN乘法表

    一.实验要求: 给定任意一个字符N(N>0),然后打印NxN的倒序乘法表. 二.解决问题: #/!bin/bash# #define functionNxN_fun(){ local i=$1 ...