--- local/fixproc.orig Wed May 25 01:23:54 2005 +++ local/fixproc Wed Nov 30 12:16:05 2005 @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!%%PERL%% # # fixproc [-min n] [-max n] [-check | -kill | -restart | -exist | -fix] proc ... # @@ -131,7 +131,7 @@ use File::Temp qw(tempfile); -$database_file = '/local/etc/fixproc.conf'; +$database_file = '%%PREFIX%%/etc/fixproc.conf'; $debug = 0; # specify debug level using -dN # currently defined: -d1 @@ -157,6 +157,14 @@ $shell_header = "#!/bin/sh\n"; $shell_end_marker = 'shell_end_marker'; +open(command, "/bin/ps -p $$ |") || die "$0: can't run ps command\n"; +if (split(' ', ) > 4) { + $ps_opts = 'ax'; +} else { + $ps_opts = '-e'; +} +close command; + &read_args(); &read_database(); # &dump_database(); # debug only @@ -305,41 +313,47 @@ # first try kill $! = $fixproc_error; - open (COMMAND, "/bin/ps -e | /bin/grep $proc |") + open (COMMAND, "/bin/ps $ps_opts |") || die "$0: can't run ps-grep-awk command\n"; while () { - # match the first field of ps -e + if /$proc/ { + # match the first field of ps $ps_opts $! = $fixproc_error; - /^\s*(\d+)\s/ || die "$0: can't match ps -e output\n"; - system "kill $1"; + /^\s*(\d+)\s/ || die "$0: can't match ps $ps_opts output\n"; + kill 15, $1; + } } + close COMMAND; # if process still exist, try kill -9 sleep 2; $! = $fixproc_error; - open (COMMAND, "/bin/ps -e | /bin/grep $proc |") + open (COMMAND, "/bin/ps $ps_opts |") || die "$0: can't run ps-grep-awk command\n"; $second_kill_needed = 0; while () { - # match the first field of ps -e + if /$proc/ { + # match the first field of ps $ps_opts $! = $fixproc_error; - /^\s*(\d+)\s/ || die "$0: can't match ps -e output\n"; - system "kill -9 $1"; + /^\s*(\d+)\s/ || die "$0: can't match ps $ps_opts output\n"; + kill 9, $1; $second_kill_needed = 1; } + close COMMAND; return ($no_error) if ($second_kill_needed == 0); # see if kill -9 worked sleep 2; $! = $fixproc_error; - open (COMMAND, "/bin/ps -e | /bin/grep $proc |") + open (COMMAND, "/bin/ps $ps_opts |") || die "$0: can't run ps-grep-awk command\n"; while () { # a process still exist, return error - return $cannot_kill_error; + return $cannot_kill_error if /$proc/; } + close COMMAND; return $no_error; # good, all dead }