找出文件中每小时最大利用率值
来源:互联网 发布:mac 触摸板 鼠标 消失 编辑:程序博客网 时间:2024/05/17 08:19
#include <stdio.h>#include <stdlib.h>#include <string.h>void jobs(char *arg1,FILE *fp) { int i,ret; char *p,*str,str1[1024]="0"; char readbuf[1024]; char c; int n=0; float max=0,value; while(fgets(readbuf,1023,fp)!=NULL) { if(strstr(readbuf,arg1)) { n++; for(p=strtok(readbuf," ");p;p=strtok(NULL," ")) str=p; str[strlen(str)-2]=0; /* sprintf(&c,"%c",str[0]); if(c=='.') { */ if(str[0]=='.') { strcat(str1,str); value=atof(str1); // printf("%.2f\n",atof(str1)); } else { value=atof(str); // printf("%.2f\n",atof(str)); } if(max<value) max=value; if(n%4==0) printf("%.2f\n",max); strcpy(str1,"0"); } } fseek(fp,0,SEEK_SET); printf("\n");} int main(int argc,char *argv[]) { int i,ret; FILE *fp; if(argc<2) { printf("%s filename...\n",argv[0]); exit(-1); } for(i=1;i<=argc-1;i++) { fp=fopen(argv[i],"r"); if(fp==NULL) { fprintf(stderr,"fopen() error.\n"); exit(-1); } printf("file=%s\n%s max:\n",argv[i],"cpu"); jobs("cpu",fp); //fseek(fp,0,SEEK_SET); printf("%s max:\n","mem"); jobs("mem",fp); //fseek(fp,0,SEEK_SET); printf("%s max:\n","swap"); jobs("swap",fp); //fseek(fp,0,SEEK_SET); ret=fclose(fp); if(ret==EOF) { fprintf(stderr,"fopen() error.\n"); exit(-1); } printf("-------------------------\n"); } exit(0);}
文件内容:$ head 0705.txt-bak (每15分钟一次) 07-05 00:00the usage of cpu is 2.2%the usage of mem is 16.678800%the usage of swap is .411200%07-05 00:15the usage of cpu is .9%the usage of mem is 16.378300%the usage of swap is .394600%07-05 00:30the usage of cpu is 12.2%the usage of mem is 17.535100%the usage of swap is .394700%07-05 00:45the usage of cpu is 12.4%the usage of mem is 17.657800%the usage of swap is .406600%
- 找出文件中每小时最大利用率值
- 找出指定目录中最大的几个文件
- 100G的大文件中找出最大的100个数
- I/O Stream<找出文件中最大与最小的整数>
- linux中在当前目录下找出占用空间最大的前10大文件
- 找出一组整数中最大的那个
- 找出数据库中size最大的表
- 118.在数组中找出最大元素
- java__for找出数组中最大,最小值
- 300.21找出Person中年龄最大的
- log4j每天,每小时产生一日志文件
- 找出3值中最大的值,用最少的代码实现
- 单链表中一趟遍历找出值最大节点
- 找出最大的5个值。
- 找出数组中的最大(小)值
- 找出表中重复数据中最大日期的数据
- 20.找出矩阵中最大的数存入数组中
- 找出10个最大的文件并排序
- 字符串函数源代码分析与比较
- 【转】用JS实现弹出模式对话框,实现页面传值
- JAX-RS之与XML打交道
- JAX-RS之jackson去处理json
- JAX-RS之resteasy跟spring整合
- 找出文件中每小时最大利用率值
- 合并排序
- 几个重要的TCP/IP选项解析(Java Socket)
- poj 2352 Star
- 用于ARM上的FFT与IFFT源代码(C语言,不依赖特定平台)
- 浪潮实习8.6
- tslib1.0移植
- 双缓冲技术绘图
- 我的博客开通了