⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 times.c

📁 这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易于我们学习和理解
💻 C
字号:
#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <sys/times.h>#include <unistd.h>#include <errno.h>#include <string.h>#include <stdlib.h>staticchar*skip(char *p){	while(*p == ' ')		p++;	while(*p != ' ' && *p != 0)		p++;	return p;}clock_ttimes(struct tms *buf){	char b[200], *p;	int f;	unsigned long r;	memset(b, 0, sizeof(b));	f = open("/dev/cputime", O_RDONLY);	if(f >= 0) {		lseek(f, SEEK_SET, 0);		read(f, b, sizeof(b));		close(f);	}	p = b;	if(buf)		buf->tms_utime = atol(p);	p = skip(p);	if(buf)		buf->tms_stime = atol(p);	p = skip(p);	r = atol(p);	if(buf){		p = skip(p);		buf->tms_cutime = atol(p);		p = skip(p);		buf->tms_cstime = atol(p);	}	return r;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -