times返回的buf中的结构体成员的值为什么每次都是0
#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
...全文
相关推荐
C语言中用于修改文件的存取时间的函数使用
这篇文章主要介绍了C语言中用于修改文件的存取时间的函数使用,分别为utime()函数和utimes()函数的使用,需要的朋友可以参考下
《Linux系统调用:times,clock》
一、介绍 软件时钟(jiffies) 系统调用的精度受限于系统软件时钟,度量单位是jiffies,定义在内核代码的常量是HZ,这是CPU分配给进程的单位。 进程时间是由一个进程使用的CPU时间量,分为用户时间和系统时间。可以用time命令查看运行的时间 yexiang@ubuntu:<_Sys>$ time ./a.out real 0m0.009s user ...
Linux服务器编程之utime()函数修改文件存取时间
本文给大家分享的是Linux服务器编程的utime()函数的用法以及修改文件存取时间的方法,有需要的小伙伴可以参考下
实现数字滤波的C语言程序
文章主要介绍了实现数字滤波的C语言程序
摄像头v4l2编写,实现视频在帧缓冲显示(非程序,文档资源)
摄像头v4l2编写,实现视频在帧缓冲显示


