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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
--- 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(' ', <command>) > 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 (<COMMAND>)
{
- # 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 (<COMMAND>)
{
- # 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 (<COMMAND>)
{ # a process still exist, return error
- return $cannot_kill_error;
+ return $cannot_kill_error if /$proc/;
}
+ close COMMAND;
return $no_error; # good, all dead
}
|