求:编写一个计算密集型的程序替代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。注释程序主要语句。
#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
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28