Hi guy, i have this little program:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
//Obtem o nome do buffer de trade baseado na hora
char *btfile() {
char *fname;
fname = malloc(14);
time_t t = time(NULL);
struct tm *lt;
lt = localtime(&t);
strftime(fname, 14, "%m%d%H%M.tbf", lt);
return fname;
}
/*
*
*/
int main(int argc, char** argv) {
//Caminho dos arquivos
char *fpath;
fpath = malloc(17);
strcpy(fpath, "/home/donda/ddc/");
//Arquivo de buffer
FILE *fbf;
//Buffer de leitura
char *b;
//Caminho completo
char *ffull;
//Aloca buffer de leitura na memoria
b = malloc(500);
//Aloca destino completo
ffull = malloc(26);
//Gera caminho
strcpy(ffull, fpath);
strcat(ffull, btfile());
//Abre Arquivo
fbf = fopen(ffull, "r");
//Verifica se abriu
if (!fbf) {
//Forca retorno ao inicio
exit(1);
}
while(fgets(b,500,fbf) != NULL){
printf("%s",b);
bzero(b,500);
}
return (EXIT_SUCCESS);
}
When I run this program, my cpu usage jump from 1% to 70%.
I'm worry with this big usage just for a little program, anyone have some advice?
Thanks