hi
i'm struggling to calculate idle time of cpu and if idle time is
more then i have to shut down the system. can anyone tell me the idea
to do that please
Hi Ram,
This would os specific though. I don't think c provides any function
that can be applied at generic level (across all os) to get the cpu
details . However you can use the popen method defined in stdio.h to
get the same
For instance on Linux you can do the following
fp = popen("top", "r");
if (fp == NULL)
/* Handle error */;
while (fgets(path, BUFF, fp) != NULL){
/*fgets would get you the cpu info . You have to do the parsing to
get the CPU info and apply your condition checking */
printf("%s", path);
}
However if you are good at perl then this can be done 10 times easier .