Solved

Linux: get wcpu from top

Posted on 2013-11-20
5
445 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

689 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