+ -
当前位置:首页 → 问答吧 → 飞思卡尔和微芯都推出了linux版本下的开发工具

飞思卡尔和微芯都推出了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 }
附件:

time.png [ 20.94 KiB | 被浏览 8 次 ]

作者: dtczhl   发布时间: 2011-10-16

热门下载

更多