[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [cobalt-users] CPU overload.... URGENT SOLUTION ANYONE?
- Subject: Re: [cobalt-users] CPU overload.... URGENT SOLUTION ANYONE?
- From: "Michael D. Schleif" <mds-resource@xxxxxxxxxxxx>
- Date: Fri Jan 26 21:42:28 2001
- Organization: mds resource
- List-id: Mailing list for users to share thoughts on Cobalt products. <cobalt-users.list.cobalt.com>
Mea culpa!
"Michael D. Schleif" wrote:
>
> #!/usr/bin/perl -w
>
> # kill_cpuhog.plx
> #
> # kill and log processes consuming excessive %CPU
> #
> # v1.0, mds (20010126)
>
> use strict;
>
> # Notice, we are *NOT* interested in processes owned by root ;<
> my $gather = 'ps -U root -u root -N -o %cpu,pid,time,user,args -U root
> -u root';
TWO (2) PREVIOUS LINES SHOULD BE ONE (1)
> my $header;
> my %kill;
> my $log = '/tmp/kill_cpuhog.log';
> my $percent = 90;
>
> # Gather list of usual suspects
> open LIST, "$gather |"
> or die "\n\tERROR: Cannot invoke \'$gather\' : $! : $?\n\n";
> chomp(my @list = <LIST>);
> close LIST;
>
> # %CPU > $percent ???
> for (@list) {
> $header = $_, next unless $header;
> my @ps = split;
> $ps[0] > $percent
> or next;
> $kill{$ps[1]} = $_;
> }
>
> # Nothing to do unless %kill has entries
> exit 0 unless %kill;
>
> # Log all that we do to $log
> open LOG, ">>$log"
> or die "\n\tERROR: Cannot write to \'$log\' : $! : $?\n\n";
> print LOG scalar localtime, "\n";
> print LOG $header, "\n";
>
> # kill -9 offending processes
> for my $pid (keys %kill) {
> print LOG $kill{$pid}, "\n";
> my $cmd = "kill -9 $pid";
REMOVE ONE (1) FOLLOWING LINE:
> $cmd = "ps -fp $pid";
I FORGOT TO REMOVE THIS LINE USED FOR TESTING ;<
> for (@{ get_sys($cmd) }) {
> print LOG $_, "\n"
> }
> }
> close LOG;
>
> exit 0;
>
> ##################
> # Sub Routines #
> ##################
>
> ##########################################
> # Get output from system level program #
> ##########################################
> sub get_sys {
> my $prog = shift;
> open PROG, "$prog 2>&1 |" or warn "\n\tERROR: Cannot invoke \'$prog\' !
> : ", $? >> 8, "\n\n";
TWO (2) PREVIOUS LINES SHOULD BE ONE (1)
> chomp(my @out = <PROG>);
> close PROG;
> return \@out;
> }
--
Best Regards,
mds
mds resource
888.250.3987
"Dare to fix things before they break . . . "
"Our capacity for understanding is inversely proportional to how much we
think we know. The more I know, the more I know I don't know . . . "