Process: add subprocess parameter to kill()

fix CommandReader subprocess lingering on a crash and fucking up the console
This commit is contained in:
Dylan K. Taylor 2021-10-02 16:56:24 +01:00
parent 2566123e49
commit dd0c2fed82
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
4 changed files with 9 additions and 6 deletions

View File

@ -300,7 +300,7 @@ JIT_WARNING
if(ThreadManager::getInstance()->stopAll() > 0){
$logger->debug("Some threads could not be stopped, performing a force-kill");
Process::kill(Process::pid());
Process::kill(Process::pid(), true);
}
}while(false);

View File

@ -1371,7 +1371,7 @@ class Server{
}catch(\Throwable $e){
$this->logger->logException($e);
$this->logger->emergency("Crashed while crashing, killing process");
@Process::kill(Process::pid());
@Process::kill(Process::pid(), true);
}
}
@ -1501,7 +1501,7 @@ class Server{
echo "--- Waiting $spacing seconds to throttle automatic restart (you can kill the process safely now) ---" . PHP_EOL;
sleep($spacing);
}
@Process::kill(Process::pid());
@Process::kill(Process::pid(), true);
exit(1);
}

View File

@ -125,18 +125,21 @@ final class Process{
return count(ThreadManager::getInstance()->getAll()) + 2; //MainLogger + Main Thread
}
public static function kill(int $pid) : void{
public static function kill(int $pid, bool $subprocesses) : void{
$logger = \GlobalLogger::get();
if($logger instanceof MainLogger){
$logger->syncFlushBuffer();
}
switch(Utils::getOS()){
case Utils::OS_WINDOWS:
exec("taskkill.exe /F /PID $pid > NUL");
exec("taskkill.exe /F " . ($subprocesses ? "/T " : "") . "/PID $pid");
break;
case Utils::OS_MACOS:
case Utils::OS_LINUX:
default:
if($subprocesses){
$pid = -$pid;
}
if(function_exists("posix_kill")){
posix_kill($pid, 9); //SIGKILL
}else{

View File

@ -50,7 +50,7 @@ class ServerKiller extends Thread{
});
if(time() - $start >= $this->time){
echo "\nTook too long to stop, server was killed forcefully!\n";
@Process::kill(Process::pid());
@Process::kill(Process::pid(), true);
}
}