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
4 changed files with 9 additions and 6 deletions

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{