Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to find CPU Usage

Status
Not open for further replies.

hecker

Programmer
May 15, 2000
8
0
0
US
How can one find the %CPU Usage for a process. I don't want to use TOP command as it seems that the statistics provided by this command are based on some kind of hysteresis. I want to find the CPU processing time taken by a process upto max accuracy.

Thanx,
Hecker
 

You can use the struct acct defined in <sys/acct.h>.
Normally process accounts are kept in /var/adm/pacct.
You can read in the file inside your process to an acct
struct and print out the contents you need.

Try the man pages of 'acct' to get more information.

Anand :cool: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mail me at abpillai@excite.com if you want additional help. I dont promise that I can solve your problem, but I will try my best.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Thanks Anand !!! for the useful tip.

we can use acctcom command with option -h to find
out % of CPU time used by a process during its execution.

thanx
hecker
 
Hi !

This is Raj,

you can use getrusage system posix to calculate the
cpu usage for child process or parent .


i.e int getrusage (int who, struct rusage *usage);
and include following files in ur program.
#include <sys/time.h>
#include <sys/resource.h>
#include <unistd.h>


Hope this will work,

Regards,
Rajesh Mistri

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top