312
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <unistd.h>
#include <sys/types.h>
#include <wait.h>
#include <glob.h>
#include <sys/times.h>
#include <time.h>
extern char **environ;
int main(int argc, char *argv[])
{
glob_t globres;
int i = 0;
struct tms startbuf;
struct tms endbuf;
long int start,end;
if ((start=times(&startbuf) )== -1)
{
perror("times()");
exit(1);
}
long clockticks = sysconf(_SC_CLK_TCK);
if (argc < 2)
{
fprintf(stderr, "Usage:%s <file> <argument>\n", argv[0]);
exit(1);
}
pid_t pid;
pid = fork();
if (pid < 0)
{
perror("fork()");
exit(1);
}
if (pid == 0) // 子进程
{
for (i = 1; i < argc; i++)
{
if (i == 1)
glob(argv[i], GLOB_NOCHECK, NULL, &globres);
else
glob(argv[i], GLOB_NOCHECK | GLOB_APPEND, NULL, &globres);
}
execvp(argv[1], globres.gl_pathv);
perror("execvp()");
exit(1);
}
else if (pid > 0) // 父进程
{
wait(NULL);
if ((end=times(&endbuf)) == -1)
{
perror("times()");
exit(1);
}
printf("start=%ld end=%ld clock_per=%ld\n",start,end,clockticks);
//访问里面的时间还是0?
printf("%ld\n%ld\n%ld\n%ld\n", startbuf.tms_cstime, startbuf.tms_cutime, startbuf.tms_stime, startbuf.tms_utime);
printf("%ld\n%ld\n%ld\n%ld\n", endbuf.tms_cstime, endbuf.tms_cutime, endbuf.tms_stime, endbuf.tms_utime);
//printf("real %fs\nuser %fs\nsys %fs\n",(double)((buf.tms_cutime+buf.tms_cstime)/clockticks) \
,(float)(buf.tms_cutime/clockticks),(float)(buf.tms_cstime/clockticks));
}
exit(0);
}
为什么我的endbuf.tms_cstime和startbuf.tms_cstime全是0,endbuf和startbuf里面的成员的值为什么都为0