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
Solved

Linux: get wcpu from top

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
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 how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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…

839 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