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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cpu,mem usage

Status
Not open for further replies.

vti

Technical User
Feb 26, 2001
189
TR

Hi,
I use ps command to see usage of mem or cpu and sort it as bigger to smaller count .But is there a way to calculate total count of usage.I mean ;

%CPU
283.0
63.3
12.4
6.9
6.6
5.5
+ 5.4
-------
?

How can i find to total count of cpu usage without using Top or something different utility.I want to usa a script for this

Thanks a lot.

 
Be sure what you are doing is correct first...283% of CPU ? How are you getting that number ?

Here is a basic script...

#!/bin/ksh
x=0
y=0
for i in `ps aux -v "%CPU"|grep -v kproc|awk {'print $3'}`
do
x=`echo "scale=2;$x+$i"|bc -l`
y=`expr $y + 1`
done

z=0
for i in `ps aux -v "%CPU"|grep -v kproc|awk {'print $4'}`
do
z=`echo "scale=2;$z+$i"|bc -l`
done

echo "Total processes: $y"
echo "Total RAM resources: $z"
echo "Total CPU resources: $x"


Bill.
 
Hi bjverzal
Thanks for answer. 283% is the cpu usage of my database on unix.

CPU part of script works well but the mem usage didn't work ,i think it happens because of u use two times %CPU, i changed the %CPU as %MEM but didn't work.Do i need to kproc as well.

Thanks.

 
Seems to me there's a red herring here. The 283% is spurious as the other figs add up to 100.1% - more like something you would expect to see accounting for rounding errors. Exactly how are you deriving this data?
 
But i got 6 cpu on my machine so i don't think is too much .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top