+ -
当前位置:首页 → 问答吧 → 求:编写一个计算密集型的程序替代grep

求:编写一个计算密集型的程序替代grep

时间:2011-10-19

来源:互联网

/* process using time */
#include<stdio.h>
#include<stdlib.h>
#include<sys/times.h>
#include<time.h>
#include<unistd.h>

void time_print(char *,clock_t);

int main(void)
{
clock_t start,end;
struct tms t_start,t_end;
start = times(&t_start);
system(“grep the /usr/doc/*/* > /dev/null 2> /dev/null”);
end=times(&t_end);

time_print(“elapsed”,end-start);
puts(“parent times”);
time_print(“\tuser CPU”,t_end.tms_utime);
time_print(“\tsys CPU”,t_end.tms_stime);

puts(“child times”);
time_print(“\tuser CPU”,t_end.tms_cutime);
time_print(“\tsys CPU”,t_end.tms_cstime);

exit(EXIT_SUCCESS);
}

void time_print(char *str, clock_t time)
{
long tps = sysconf(_SC_CLK_TCK);
printf(“%s: %6.2f secs\n”,str,(float)time/tps);
}
求:编写一个计算密集型的程序替代grep。注释程序主要语句。

作者: xul2009   发布时间: 2011-10-19

帮顶..

作者: abao623660072   发布时间: 2011-10-20

热门下载

更多