A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2005-04-16 06:51 PM

Registered: 2005-04-11
Posts: 12

Re: measure CPU usage


i'm facing another problem concerning gathering statistics about system. This time be it CPU & RAM. Reading getrusage() and another thread here, the RAM thingy seems easy. However, what about the CPU. There is the user time field of getrusage, can I use it somehow like this to obtain some cool stats?

say, I got numerous threads that can execute custom functions I supply. Think something like this may work and produce the %cpu usage of that custom function?:

void ThreadStart() {
     begintime = currenttime;
     beginusage = getrusage(user time);


     endusage = getrusage(user time);

     percentage = (endusage - beginusage) / (currenttime - begintime)

another is, how to find out the total usage of the CPU% by the whole system?(not just my processes and the children) and what about more CPUs

I boldly tried to determine how to do this from the procps code... but well that code looks.. 'funky'


#2 2005-04-18 08:47 AM

From: Sol 3
Registered: 2002-06-12
Posts: 911

Re: measure CPU usage

To determine the "real" amount of time a function is using... check out one of the older msgs in the forum...  its at:


For load average on the machine... check out the thread at:


That call should be present on BSD, Mac OS X, Solaris, Linux... and probably others now...

If you are on Windows... all that information is kept / updated in the registery... but there is an alternative to writing seperate versions for every flavor of the Win OS...  check out the MSDN article at:

http://msdn.microsoft.com/library/defau … monpt2.asp

Hope that helps...


"The only difference between me and a madman is that I'm not mad."

Salvador Dali (1904-1989)


#3 2009-09-24 06:09 AM


Re: measure CPU usage

Will a CPU of 1066 fsb run on a motherboard that has a bus speed of only 800mhz? I'm planning on buying a new CPU in order to upgrade from my Intel Core2Duo e4300 (1.8 Ghz) which runs at 800mhz FSB. But the new CPU (intel 6600) says that it runs at 1066 FSB and my motherboard only runs up to 800Mhz.

Board footer

Powered by FluxBB