Solved

Linux: get wcpu from top

Posted on 2013-11-20
5
428 Views
Last Modified: 2013-11-20
top -bn 1

Open in new window

This returns %CPU usage for each process.  How can I get the %WCPU usage instead?
0
Comment
Question by:hankknight
  • 3
  • 2
5 Comments
 
LVL 19

Expert Comment

by:simon3270
ID: 39662526
You probably can't, without changing the code within "top".  I've only come across WCPU in the HPUX version of "top".
0
 
LVL 19

Accepted Solution

by:
simon3270 earned 500 total points
ID: 39662559
An alternative is to use the "ps" command, which outputs a weighted CPU value.  Try
ps -eo "%c %C"

Open in new window

to output the command, followed by the percentage CPU.  If you wanted to produce data for later sorting, you could use
ps -eo "%c %C" | tail -n +2 | sed 's/\.//'

Open in new window

(This replaces the
    top -bn 1 | awk 'NR >= 8{split($9,a,".");print $12 " " a[1] a[2]}'
 from my answer to your "top 5 process hogs" question)
0
 
LVL 16

Author Comment

by:hankknight
ID: 39662704
 ps -eo  "%c %C"

Open in new window

This returns:
COMMAND         %CPU
php                        10.0
sftp-server              5.0
ps                            3.0
bash                        1.0
Are you sure that is wcpu and not cpu?
0
 
LVL 19

Expert Comment

by:simon3270
ID: 39663105
Hmm, not sure it is either, really.  The man page says that %cpu is the total CPU time for the process since it started, divided by the time the process has been running.  This is different from the "top" values of %CPU (the time that a process is using the CPU in a particular period, e.g. 10 seconds, divided by that period) and %WCPU (as %CPU, but weighted by some method which I can't find described clearly).

All are approximations to some extent - is there a reason why you particularly wanted WCPU?
0
 
LVL 16

Author Comment

by:hankknight
ID: 39663157
I want weighted CPU because it seems to give a better indication of processes that are have high CPU usage for longer than a very short burst.  

The values returned by your code seem to correspond to WCPU values anyway, so that is good.

Thanks!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Daily system administration tasks often require administrators to connect remote systems. But allowing these remote systems to accept passwords makes these systems vulnerable to the risk of brute-force password guessing attacks. Furthermore there ar…
How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now