eee
This commit is contained in:
@@ -5,6 +5,8 @@ namespace Kiri\Server\Processes;
|
||||
use Exception;
|
||||
use Kiri;
|
||||
use Swoole\Process;
|
||||
use const SIGKILL;
|
||||
use const SIGTERM;
|
||||
|
||||
trait TraitProcess
|
||||
{
|
||||
@@ -66,4 +68,39 @@ trait TraitProcess
|
||||
{
|
||||
return $this->_process;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function terminateProcesses(): void
|
||||
{
|
||||
$pids = [];
|
||||
foreach ($this->_process as $process) {
|
||||
$pid = (int)($process->pid ?? 0);
|
||||
if ($pid > 1 && $pid !== getmypid()) {
|
||||
$pids[] = $pid;
|
||||
}
|
||||
}
|
||||
|
||||
$pids = array_values(array_unique($pids));
|
||||
foreach ($pids as $pid) {
|
||||
if (@Process::kill($pid, 0)) {
|
||||
@Process::kill($pid, SIGTERM);
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
$alive = array_values(array_filter($pids, static fn(int $pid): bool => @Process::kill($pid, 0)));
|
||||
if ($alive === []) {
|
||||
return;
|
||||
}
|
||||
usleep(100000);
|
||||
}
|
||||
|
||||
foreach ($pids as $pid) {
|
||||
if (@Process::kill($pid, 0)) {
|
||||
@Process::kill($pid, SIGKILL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user