Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Monitor one task's CPU usage via top' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Monitor one task's CPU usage via top
Authored by: Whosawhatsis on Nov 17, '04 01:17:34AM

I will never understand why people do a bunch of greps in a row combined with other stuff when a single awk will do... well, at least they didn't throw an awk in with the other stuff...

---
I was offered a penny for my thoughts, so I gave my two cents... I got ripped off.



[ Reply to This | # ]
Monitor one task's CPU usage via top
Authored by: kirkmc on Nov 17, '04 04:24:52AM

Can you tell us how to do it with awk? I find awk unbearably confusing... Especially since you are dealing with multiple lines here.

But, hey, the joy of the command line is that there are so many different ways to get the same results!

---
Read my blog: Kirkville -- http://www.mcelhearn.com
Musings, Opinion and Miscellanea, on Macs, iPods and more



[ Reply to This | # ]
Monitor one task's CPU usage via top
Authored by: bimtob on Nov 17, '04 02:36:30PM
I prefer perl. Don't know awk regex :)
My geektools...

Uptime
uptime | perl -p -e 's/^(.+?up\s+?)(\d+.+?)(\,\s+\d+\s+user.+)(.*)$/Uptime: $2/'
Load
uptime | perl -p -e 's/^(.*?)(\d\.\d\d\s\d\.\d\d\s\d\.\d\d)$/Load Avgs: $2/'
I also wrote a calendar script that looks better than the default cal output, and use Geektool to put it on my desktop. OSX should have an option to show the date in the menu bar (without clicking), but until then I use this.

It prints:

   November 17 2004
  S  M Tu  W Th  F  S
     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
The script:

#!/usr/bin/perl

use POSIX qw/strftime/;
use integer;

$date = strftime "%e",localtime;
$date =~ s/\s//;
@cal = `cal`;
$cal[0] = (strftime "%B %e %Y", localtime)."\n";
$cal[0] =~ s/\s\s/ /;
$il = " " x ((length($cal[1]) - length($cal[0]))/2);
$cal[0] =~ s/^/ $il/; 
print $cal[0];
for ($i = 1; $i <=6; $i++) {
        $cal[$i] =~ s/^(.*)\n$/ $1/;
        $cal[$i] =~ s/(^|\s)$date(\s|$)/\[$date\]/;
        print $cal[$i]."\n";
}


[ Reply to This | # ]