随笔分类 - 系统编程
摘要:程序读取磁盘上的数据只能通过系统调用read,而read得代码在内核中,所以当read调用发生时,执行权会从用户代码转移到内核代码,而这种来回的切换也是需要时间的,因此可以设置缓冲区以减少切换所带来的时间消耗。//who.c文件#include <stdio.h>#include <utmp.h>#include <fcntl.h>#include <unistd.h>#include <time.h>#define SHOWHOSTvoid showtime(long);void show_info(struct utmp*);vo
阅读全文
摘要:1.who是如何工作的who实际上是通过utmp文件来获取登陆用户的信息的#include <utmp.h>信息结构如下:#define UTMP_FILE /var/adm/utmp#define ut_name ut_userstruct utmp{ char ut_user[32];//登录名 char ut_id[14]; char ut_line[32];//设备名 short ut_type;//入口类型 pid_t ut_pid;//进程id struct exit_status{ short e_termination; ...
阅读全文

浙公网安备 33010602011771号