Fun with the top command...

The top command can give you up-to-the-second reporting of system load, memory usage, 
and CPU utilization.

simply run top from the command line

$ top

Hit ? while top is running to get a list of available commands. A couple of very 
useful display keys are M (which sorts on resident memory size), P (which sorts by CPU 
usage again), S (to toggle cumulative runtime, that is, how long each process and all 
its children have been running, in CPU seconds), and i (to stop displaying idle 
processes)

as root
u key lets you filter out all processes except those owned by a given user. Follow 
that up with k, which lets you interactively kill a given PID (with any signal you 
like) - Can be really handy for hunting down runaway processes, and killing then from 
inside top (maybe even copying and pasting the offending PID to avoid the dreaded kill 
typo)

... and the best part

If you've managed a number of Linux servers, then you probably know what its like to 
have several tops running in multiple windows, all competing for desktop real estate. 
Why not run a process that updates the titlebar of your terminal with the current load 
average regardless of what else you're running?

Save this script called tl, and save it to your ~/bin directory:

------------------------------------------------------------------------
#!/usr/bin/perl -w


use strict;
$|++;


my $host=`/bin/hostname`;
chomp $host;

while(1)  {


open(LOAD, "/proc/loadavg")  || die "Couldn't open /proc/loadavg: $!\n";



my @load=split(/ /, <LOAD>);
close(LOAD);


print "\033]0;";
print "$host: $load[0] $load[1] $load[2]  at  ", scalar(localtime);
print "\007";

sleep 2; 
}
--------------------------------------------------------------------------

To see your titlebar replaced with the name, load average, and current time of the 
machine you're logged into, just run tl&. It will happily go on running in the 
background, even if you're running an ineractive program like vim. If you have your 
titlebar already set to show the current working directory (cwd), no problem. When you 
cd, the cwd is flashed momentarily, and then replaced with the time and load average 
again. Need to see that directory one more time? just hit Enter on a blank line, and 
it will flash again.

When finished working don't forget to killall tl before logging out. Or if you're 
terminally lazy (like me), try this:

$ echo 'killall tl > /dev/null 2>&1' >> ~/.bash_logout

That will kill all of your running tl jobs on logout, without even having to lift a 
finger. System administration just keeps getting easier, doesn't it? 



__________________________________________________________________
McAfee VirusScan Online from the Netscape Network.
Comprehensive protection for your entire computer. Get your free trial today!
http://channels.netscape.com/ns/computing/mcafee/index.jsp?promo=393397

Get AOL Instant Messenger 5.1 free of charge.  Download Now!
http://aim.aol.com/aimnew/Aim/register.adp?promo=380455


---------------------------------------------
This service is hosted on the Infocom network
http://www.infocom.co.ug

Reply via email to