resusg1.c
来自「基于网络编程的例子」· C语言 代码 · 共 42 行
C
42 行
/* * resusg1.c - Get process times */#include <stdio.h>#include <stdlib.h>#include <sys/times.h>#include <time.h>#include <unistd.h>void doit(char *, clock_t);int main(void){ clock_t start, end; struct tms t_start, t_end; start = times(&t_start); /* Redirect output to prevent screen clutter */ system("grep the /usr/doc/*/* > /dev/null 2> /dev/null"); end = times(&t_end); doit("elapsed", end - start); puts("parent times"); doit("\tuser CPU", t_end.tms_utime); doit("\tsys CPU", t_end.tms_stime); puts("child times"); doit("\tuser CPU", t_end.tms_cutime); doit("\tsys CPU", t_end.tms_cstime); exit(EXIT_SUCCESS);}void doit(char *str, clock_t time){ /* Get clock ticks/second */ long tps = sysconf(_SC_CLK_TCK); printf("%s: %6.2f secs\n", str, (float)time/tps);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?