p_ysk/stop_webman_commands.php

58 lines
1.8 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* 终止 Webman 相关进程的脚本
* 功能:根据进程名关键词杀死指定的 Webman 进程
*/
// 定义需要终止的进程关键词(与启动命令对应)
$processKeywords = [
'applysmstemp.php',
'birthdaygiftsms.php',
'rabborderprint.php',
'rabbproductupdate.php'
];
echo "开始终止 Webman 进程...\n";
echo "----------------------------------------\n";
foreach ($processKeywords as $index => $keyword) {
$processNum = $index + 1;
echo "处理进程 {$processNum}:关键词 = {$keyword}\n";
// 1. 查找包含关键词的进程 IDPID
// 命令说明:
// - ps aux列出所有进程
// - grep "{$keyword}":筛选包含关键词的进程
// - grep -v grep排除 grep 自身进程
// - awk '{print $2}':提取 PID第 2 列)
$cmd = "ps aux | grep '{$keyword}' | grep -v grep | awk '{print $2}'";
exec($cmd, $pids); // 执行命令并获取所有匹配的 PID
if (empty($pids)) {
echo "未找到进程:{$keyword}\n";
echo "----------------------------------------\n";
continue;
}
// 2. 逐个杀死进程
foreach ($pids as $pid) {
$pid = trim($pid);
if (is_numeric($pid)) {
// 先尝试正常终止SIGTERM失败则强制终止SIGKILL
$killResult = exec("kill {$pid}");
if ($killResult === '') {
echo "成功终止进程 PID={$pid}\n";
} else {
// 正常终止失败,强制杀死
exec("kill -9 {$pid}");
echo "强制终止进程 PID={$pid}\n";
}
}
}
echo "----------------------------------------\n";
}
echo "所有进程处理完毕!\n";
echo "可通过 'ps aux | grep webman' 确认是否已终止。\n";