Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Linux: get wcpu from top

Posted on 2013-11-20
5
Medium Priority
?
459 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 20

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 20

Accepted Solution

by:
simon3270 earned 2000 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 20

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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.
Suggested Courses

604 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