刘喆君

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

第九周学习总结

  • 管家婆与服务生
  • 管家婆
    • 通过【文件】对I/O设备进行抽象
    • 通过【虚存】对主存和I/O设备进行了抽象
    • 通过【进程】对CPU、主存和I/O设备进行了抽象
  • 服务生
  • GUI:为小白用户提供服务
  • shell:为高级用户提供服务,需要记忆系统命令
  • 系统调用:为专业用户程序员提供服务

命令总结

  1. man -k key1|grep key2|grep key3|...搜索查询帮助
  2. man 2在系统中调用查找命令
  3. whatis 关键字查看帮助
  4. man -f 关键字查找帮助
  5. cp source-file target-file修改或复制文件
  6. od -tx1 /var/run/utmp一个字节一个字节地查看utmp文件的二进制内容
  7. cat /var/run/utmp查看utmp文件内容
  8. grep -nr XXX /usr/include查看xxx在文件夹中的定义,查找宏定义,类型定义

关于head和teal

  • 它用来显示开头或结尾某个数量的文字区块,head 用来显示档案的开头至标准输出中,而 tail 就是看档案的结尾。
  • 格式:`head [参数] [文件]
  • 参数内容
  • -q隐藏文件名
  • -v显示文件名
  • -c<字节>显示字节数
  • -n<行数>显示的行数

自己写出who命令(参考老师代码)

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

int show_info( struct utmp *utbufp )
{
	printf("%-8.8s", utbufp->ut_name);  
	printf(" ");                
	printf("%-8.8s", utbufp->ut_line);  
	printf(" ");                
	printf("%10ld", utbufp->ut_time);   
	printf("\n");               
	return 0;
}

int main()
{
	struct utmp  current_record;    
	int     utmpfd;     
	int     reclen = sizeof(current_record);
	//打开utmp 文件
	if ( (utmpfd = open(UTMP_FILE, O_RDONLY)) == -1 ){
	    perror( UTMP_FILE );    
	    exit(1);
	}

	//读取utmp中的每一条记录
	while ( read(utmpfd, &current_record, reclen) == reclen )
	    //显示记录中的相关信息
	    show_info(&current_record);

	//关闭utmp文件
	close(utmpfd);
	return 0;           
}
  • 注意:fd文件描述符可以从open中获得
posted on 2018-11-04 16:25  mushroom1111  阅读(127)  评论(0编辑  收藏  举报