运行《unix高级环境编程》中的一个例子,不过输出结果很怪,哪位大牛帮忙看下

来源:百度知道 编辑:UC知道 时间:2024/06/17 21:41:39
#include"apue.h"
#include<sys/times.h>
static void pr_times(clock_t,struct tms*,struct tms*);
static void do_cmd(char*);

int main(int argc,char *argv[]){
int i;
setbuf(stdout,NULL);
for(i=1;i<argc;i++)
do_cmd(argv[i]);
exit(0);
}

static void do_cmd(char *cmd){
struct tms tmsstart,tmsend;
clock_t start,end;
int status;

printf("\ncommand:%s\n",cmd);
if((start=times(&tmsstart))==-1)
err_sys("time error");
if((status=system(cmd))<0)
err_sys("system() error");

if((end=times(&tmsend))==-1)
err_sys("times error");
pr_times(end-start,&tmsstart,&tmsend);
pr_exit(status);

}

static void pr_times(clock_t real,struct tms *tmsstart,struct tms *tmsend){
static long clktck=0;
if(clktck==0)
if((clktck==sysconf(_SC_CLK_TCK))<0)

那里是你的输出结果?把题目也说清吗。
如果我没猜错的话,你是奇怪为什么输出“nan”吧!那是因为你要执行运算的一些变量,由于你的程序错了,从而没有被赋值(或没有运算)。从而只能输出一个默认的代表空的字符串“nan”。

程序错误