i want to write a c code to get system information like cpu and memory in linux i don't know how pliz help.
How can i get system information with c in linux?
void sysinfo()
{
char *buf=(char*) malloc(sizeof(char)*255);
FILE* finfo;
int lines=31;
finfo=fopen("/proc/cpuinfo","r");
while(lines%26gt;0)
{
fscanf(finfo,"%s",tempbuf);
printf("%s ",tempbuf);
lines--;
}
fclose(finfo);
printf("\n");
lines=12;
finfo=fopen("/proc/meminfo","r");
while(lines%26gt;0)
{
fscanf(finfo,"%s",tempbuf);
printf("%s ",tempbuf);
if(strcmp(tempbuf,"kB")==0)
printf("\n");
lines--;
}
printf("\n");
fclose(finfo);
free(buf);
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment