Re: Cleaning up processes on Solaris system

From: shyamkm@hydbad.tcs.co.in
Date: Fri Nov 29 2002 - 07:15:50 EST


Hi Sunmanagers,
     Thanks to all those who have replied. This mail is to summarise the
temporary solution, we have implemented for the problem.

     We had problems with some processes(of some applications) lying around
on our Solaris 8 systems, even after the applications are closed/exited. We
couldn't yet find the reason why this is happening. However we could put up
a script to clean the processes every few hours. Thanks to Kevin, for
providing the script (in the enclosed mail). We have customised the script
to check some more conditions (so as to not to kill required processes) and
implemented the script.

Regards
Shyam Kumar M
----- Forwarded by M Shyam Kumar/IDM/TCSHYDERABAD/TCS on 11/29/2002 05:41
PM -----
                                                                                                                                
                    "Kevin P.
                    Inscoe To: shyamkm@hydbad.tcs.co.in
                    (KE3VIN)" cc:
                    <kevin@inscoe Subject: Re: Cleaning up processes on Solaris system
                    .org>
                                                                                                                                
                    11/28/2002
                    08:47 PM
                                                                                                                                
                                                                                                                                

shyamkm@hydbad.tcs.co.in wrote:

> Also, meanwhile I am trying to put up a scheduled script to look for
> the processes that are lying around (probably checking to see if there
are
> processes lying around sleeping while the application is closed, for some
> number of hours) and then kill those processes, so as to clean the
system.
> If anyone is already having such a script, can help me by providing me
the
> script.

Yup I do. You will need Perl 5.6 or later and install the Perl module
Proc-ProcessTable-0.35 from the CPAN.

http://www.perl.com/cpan

Anyway the script is here:

#!/usr/local/bin/perl

# find processes that match name specified by first parameter if second
parameter
# is correctly formatted in seconds only processes matching passed name
and number
# of seconds old or older will be killed.
#
# Kevin P. Inscoe (kevin@inscoe.org) October 14, 2002
#
#

use Proc::ProcessTable;
use Time::localtime;

$ref = new Proc::ProcessTable;

# Check parameters for required
if ( ( @ARGV < 2 ) || ( $ARGV[1] == 0 ) ) {
        print "ageoff.pl usage:\n";
        print "\n";
        print "$0 match-name seconds-old-before-kill (integer)\n";
        print "\n";
        exit 0;
}

$killtime = time-$ARGV[1];

foreach $proc (@{$ref->table}) {
        next unless ( $proc->{cmndline} =~ m/$ARGV[0]/ ) && (
$proc->{cmndline} !~ m/$0/ );
# print "pid=$proc->{pid} start=$proc->{start}
cmd=$proc->{cmndline}\n";
        if ( $proc->{start} < $killtime ) {
                $xtime=ctime($proc->{start});
                print "Killing pid $proc->{pid} start=($xtime)
$proc->{cmndline}...\n";
                kill 9, $proc->{pid};
        }
}

Or online:

http://inscoe.org/pub/scripts/ageoff.pl.txt

HTH!

~ke3vin

--
Kevin P. Inscoe       KE3VIN        Geek and fixer of things
Deltona, FL 32738    FX/VM: 507-262-1277   28.9492N 81.1955W
kevin [at] inscoe [dot] org          http://inscoe.org/kevin
"Business! Mankind was my business."          - Jacob Marley
"I say beware of all enterprises that require new clothes,
and not rather a new wearer of clothes." - Henry Thoreau
This is Virus Free Mail from hydbad.tcs.co.in
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers


This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 23:25:22 EDT