nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

Capture Process Using Highest CPU usage

This is a discussion on Capture Process Using Highest CPU usage within the Getting started tutorials forums, part of the Linux Getting Started category; Hey, This is a string command that I am proud of. Wanted to share it with you all. I have ...

Register free or login to your existing account and remove all advertisements.


Go Back   nixCraft Linux Forum > Linux Getting Started > Getting started tutorials

Linux answers from nixCraft.


Getting started tutorials So much to read, so little time! If that is your problem, we have solution. Read our FAQ and tutorials to help you cut through the clutter of information overload. Only members of "contributors" group can post new tutorials. Other members can just reply to thread.

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-23-2010, 07:34 PM
jaysunn's Avatar
Powered By Linux
User
 
Join Date: Apr 2009
Location: 41.332032,-73.089775
OS: RHEL - OSX
Posts: 596
Thanks: 61
Thanked 78 Times in 70 Posts
Rep Power: 10
jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold jaysunn is a splendid one to behold
Default Capture Process Using Highest CPU usage

Hey,
This is a string command that I am proud of. Wanted to share it with you all. I have finally figured out how to print the process using the highest cpu. You can use this in many ways. I wanted to capture it in a variable, see third code block.

1.
Code:
[root@vmradio01 ~]# ps -eo pid,user,%cpu,args --sort %cpu | awk '/httpd/{n=n<$3?$3:n}END{print n}'
2.3
Here I separate the first field for the variable using awk:

2.
Code:
[root@vmradio01 ~]# ps -eo pid,user,%cpu,args --sort %cpu | awk '/httpd/{n=n<$3?$3:n}END{print n}' | awk -F \. '{print $1}'
2
3. Assign it to a variable called highcpuproc.
Code:
[root@vmradio01 ~]#highcpuproc=`ps -eo pid,user,%cpu,args --sort %cpu | awk '/httpd/{n=n<$3?$3:n}END{print n}' | awk -F \. '{print $1}'`
LOVE LINUX
Jaysunn
__________________
Have a look at what I have been working on
http://www.shellasaurus.com
Reply With Quote
The Following User Says Thank You to jaysunn For This Useful Post:
jerry (01-26-2010)
  #2 (permalink)  
Old 01-25-2010, 11:59 PM
Senior Member
User
 
Join Date: Jun 2005
Posts: 137
Thanks: 21
Thanked 4 Times in 3 Posts
Rep Power: 5
jerry is on a distinguished road
Default

well done my friend. I like this code
Code:
n=n<$3?$3:n
__________________
Learning shell and Perl scripting was one of best things I did..
Reply With Quote
  #3 (permalink)  
Old 03-04-2010, 04:57 AM
Junior Member
User
 
Join Date: Mar 2010
OS: Debian
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Power: 0
ngham4host is on a distinguished road
Default

thanks alot bro
Reply With Quote
Reply

Tags
cpu process capture highest


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
[Solved] Linux see ram usage for each process kumarat9pm CentOS / RHEL / Fedora 4 11-19-2009 01:15 AM
Limit CPU usage for process Red Hat jaysunn CentOS / RHEL / Fedora 2 10-28-2009 07:26 PM
list path for apache process with great cpu usage cosminnci Shell scripting 4 08-19-2008 02:21 AM
CPU usage Shell script (Monitoring CPU Usage) atulmatkar Shell scripting 2 05-10-2008 10:24 PM
AUDIO CAPTURE PROBLEM ON ARM PB926EJ-s board, Audio couldn't capture on the ARM Board fazlur Linux hardware 0 09-05-2007 05:04 PM


All times are GMT +5.5. The time now is 01:46 PM.


Powered by vBulletin® Version 3.8.4 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2009 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38