/Retreiving information from /proc
Hi there, I'm working on a program to report the behaviour of a linux kernel by printing out variables in certain files which are in /proc/
I currently have fgets reading it good just can't get strstr working properly. The current value of cpu_type is (null).
Code:
#include <stdio.h>
#include <string.h>
char get_cpu_model()
{
FILE* fp;
char buffer[4096];
char* match;
char cpu_type;
size_t bytes_read;
fp = fopen("/proc/cpuinfo", "r");
while(!feof(fp)){
fgets(buffer,sizeof(buffer),fp);
match = strstr(buffer, "model name");
printf("%s",buffer);
}
fclose (fp);
int counter = 0;
printf("\nhere1\n");
printf("%s",match);
if (match == NULL){
printf("\nNo Match\n");
return 0;
} else {
sscanf (match, "model name : %s", &cpu_type);
return cpu_type;
}
}
char main()
{
printf ("CPU Model Name: %s\n", get_cpu_model());
return 0;
}