Solved

Linux: get wcpu from top

Posted on 2013-11-20
5
433 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Guacamole cut and paste issue 3 74
Xymon customize http timeout 2 86
Ubuntu not booting - How get past GRUB? 3 43
i can not do linux commands in cygwin windows 10 6 75
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

778 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