calculation of cpu idle time

R

ram.ragu

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
 
R

ranjayap

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 .
 
F

Flash Gordon

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

<snip further off topic advice>

I can't. At least not on all of my systems, since not all of them *have*
a popen function anywhere since it is not part of the C standard.

Since the OP has not specified what system the only sensible advice it
to find a group dedicated to whatever system it is and ask there since
it can't be done in standard C which is what we discus here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top