飞思卡尔和微芯都推出了linux版本下的开发工具
时间:2011-10-16
来源:互联网
程序如下,输出结果见图,为什么所有到时间值竟然会相等阿
代码:
#include "apue.h"
2 #include <sys/times.h>
3
4 static void pr_times(clock_t,struct tms*,struct tms*);
5 static void do_cmd(char*);
6
7 int
8 main(int argc,char *argv[])
9 {
10
11 int i;
12
13 setbuf(stdout,NULL);
14 for (i=1;i<argc;i++)
15 do_cmd(argv[i]);
16 exit(0);
17
18 }
19
20 static void
21 do_cmd(char *cmd)
22 {
23 struct tms tmsstart,tmsend;
clock_t start,end;
25 int status;
26
27 printf("\ncommand: %s\n",cmd);
28
29 if ((start=times(&tmsstart))==-1)
30 err_sys("times error");
31 if ((status=system(cmd))<0)
32 err_sys("system() error");
33
34 if ((end=times(&tmsend))==-1)
35 err_sys("times error");
36
37 pr_times(end-start,&tmsstart,&tmsend);
38 pr_exit(status);
39 }
40
41 static void
42 pr_times(clock_t real,struct tms *tmsstart,struct tms *tmsend)
43 {
44 static long clktck=0;
45 if (clktck==0)
46 if ((clktck=sysconf(_SC_CLK_TCK))<0)
47 err_sys("sysconf error");
48 printf(" real: %7.2f\n",real/(double)clktck);
49 printf(" user: %7.2f\n",(tmsend->tms_utime - tmsstart->tms_utime))/(double)clktck;
50 printf(" sys: %7.2f\n",(tmsend->tms_stime - tmsstart->tms_stime))/(double)clktck;
51 printf(" child user: %7.2f\n",(tmsend->tms_cutime - tmsstart->tms_cutime))/(double)clktck;
52 printf(" child sys: %7.2f\n",(tmsend->tms_cstime - tmsstart->tms_cstime))/(double)clktck;
53
54 }
2 #include <sys/times.h>
3
4 static void pr_times(clock_t,struct tms*,struct tms*);
5 static void do_cmd(char*);
6
7 int
8 main(int argc,char *argv[])
9 {
10
11 int i;
12
13 setbuf(stdout,NULL);
14 for (i=1;i<argc;i++)
15 do_cmd(argv[i]);
16 exit(0);
17
18 }
19
20 static void
21 do_cmd(char *cmd)
22 {
23 struct tms tmsstart,tmsend;
clock_t start,end;
25 int status;
26
27 printf("\ncommand: %s\n",cmd);
28
29 if ((start=times(&tmsstart))==-1)
30 err_sys("times error");
31 if ((status=system(cmd))<0)
32 err_sys("system() error");
33
34 if ((end=times(&tmsend))==-1)
35 err_sys("times error");
36
37 pr_times(end-start,&tmsstart,&tmsend);
38 pr_exit(status);
39 }
40
41 static void
42 pr_times(clock_t real,struct tms *tmsstart,struct tms *tmsend)
43 {
44 static long clktck=0;
45 if (clktck==0)
46 if ((clktck=sysconf(_SC_CLK_TCK))<0)
47 err_sys("sysconf error");
48 printf(" real: %7.2f\n",real/(double)clktck);
49 printf(" user: %7.2f\n",(tmsend->tms_utime - tmsstart->tms_utime))/(double)clktck;
50 printf(" sys: %7.2f\n",(tmsend->tms_stime - tmsstart->tms_stime))/(double)clktck;
51 printf(" child user: %7.2f\n",(tmsend->tms_cutime - tmsstart->tms_cutime))/(double)clktck;
52 printf(" child sys: %7.2f\n",(tmsend->tms_cstime - tmsstart->tms_cstime))/(double)clktck;
53
54 }
附件: |
![]() time.png [ 20.94 KiB | 被浏览 8 次 ] |
作者: dtczhl 发布时间: 2011-10-16
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28