#include <fstream>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
using namespace std;
class file_CPU_INFO
{
private:
mode_t mode_value;
char *file_name;
float cpu_Values(char *str_Argument)
{
char *directory="/proc/cpuinfo";
char buf[512],end='\0';
FILE *m_file;
char *find;
size_t byt;
float result;
m_file=fopen(directory,"r");
byt=fread(buf,1,sizeof(buf),m_file);
fclose(m_file);
buf[byt]=end;
find=strstr(buf,str_Argument);
if(find==NULL)
return 0;
char *temp;
strcpy(temp,str_Argument);
strcat(temp," : %f");
sscanf(find,temp,&result);
return result;
}
public:
file_CPU_INFO(char *file)
{
int f1;
mode_value=S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
file_name=file;
f1=open(file_name, O_WRONLY | O_EXCL | O_CREAT,mode_value);
close(f1);
}
void Write(char *cpu_Argument)
{
float cpu_Value;
cpu_Value=cpu_Values(cpu_Argument);
fstream file(file_name,ios::out);
file<<cpu_Value;
file.flush();
file.close();
}
};
int main(int argc, char **argv)
{
int i;
string cpu_values[5]={"bogomips","cache_alignment","model","stepping","processor"};
file_CPU_INFO my_CPU("cpu_file");
for(i=0;i<5;i++)
{
my_CPU.Write(strdup(cpu_values[i].c_str()));
}
return 0;
}
Brak komentarzy:
Prześlij komentarz