Revision ba8495f0
Added by Ermal LUÇI almost 15 years ago
etc/inc/util.inc | ||
---|---|---|
50 | 50 |
} |
51 | 51 |
|
52 | 52 |
function is_process_running($process) { |
53 |
$running = shell_exec("/bin/pgrep -x {$process}");
|
|
53 |
system("/bin/pgrep -x {$process}", $retval);
|
|
54 | 54 |
|
55 |
return !empty($running);
|
|
55 |
return (intval($retval) == 0);
|
|
56 | 56 |
} |
57 | 57 |
|
58 | 58 |
function isvalidproc($proc) { |
59 |
$running = is_process_running($proc); |
|
60 |
if (intval($running) >= 1) |
|
61 |
return true; |
|
62 |
else |
|
63 |
return false; |
|
59 |
return is_process_running($proc); |
|
64 | 60 |
} |
65 | 61 |
|
66 | 62 |
/* sigkill a process by pid file */ |
67 | 63 |
/* return 1 for success and 0 for a failure */ |
68 | 64 |
function sigkillbypid($pidfile, $sig) { |
69 |
if (is_file($pidfile)) { |
|
70 |
$pid = trim(file_get_contents($pidfile)); |
|
71 |
if(isvalidpid($pid)) |
|
72 |
return mwexec("/bin/kill -s $sig {$pid}", true); |
|
73 |
} |
|
65 |
if (is_file($pidfile)) |
|
66 |
return mwexec("/bin/pkill -{$sig} -F {$pidfile}", true); |
|
67 |
|
|
74 | 68 |
return 0; |
75 | 69 |
} |
76 | 70 |
|
Also available in: Unified diff
Ticket #485. Correct code and use pkill/pgrep to match or kill process. Since these utilities know how to handle pidfiles and exact matches on process names.