mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-03 08:39:53 +00:00
Process: add subprocess parameter to kill()
fix CommandReader subprocess lingering on a crash and fucking up the console
This commit is contained in:
parent
2566123e49
commit
dd0c2fed82
@ -300,7 +300,7 @@ JIT_WARNING
|
|||||||
|
|
||||||
if(ThreadManager::getInstance()->stopAll() > 0){
|
if(ThreadManager::getInstance()->stopAll() > 0){
|
||||||
$logger->debug("Some threads could not be stopped, performing a force-kill");
|
$logger->debug("Some threads could not be stopped, performing a force-kill");
|
||||||
Process::kill(Process::pid());
|
Process::kill(Process::pid(), true);
|
||||||
}
|
}
|
||||||
}while(false);
|
}while(false);
|
||||||
|
|
||||||
|
@ -1371,7 +1371,7 @@ class Server{
|
|||||||
}catch(\Throwable $e){
|
}catch(\Throwable $e){
|
||||||
$this->logger->logException($e);
|
$this->logger->logException($e);
|
||||||
$this->logger->emergency("Crashed while crashing, killing process");
|
$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;
|
echo "--- Waiting $spacing seconds to throttle automatic restart (you can kill the process safely now) ---" . PHP_EOL;
|
||||||
sleep($spacing);
|
sleep($spacing);
|
||||||
}
|
}
|
||||||
@Process::kill(Process::pid());
|
@Process::kill(Process::pid(), true);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,18 +125,21 @@ final class Process{
|
|||||||
return count(ThreadManager::getInstance()->getAll()) + 2; //MainLogger + Main Thread
|
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();
|
$logger = \GlobalLogger::get();
|
||||||
if($logger instanceof MainLogger){
|
if($logger instanceof MainLogger){
|
||||||
$logger->syncFlushBuffer();
|
$logger->syncFlushBuffer();
|
||||||
}
|
}
|
||||||
switch(Utils::getOS()){
|
switch(Utils::getOS()){
|
||||||
case Utils::OS_WINDOWS:
|
case Utils::OS_WINDOWS:
|
||||||
exec("taskkill.exe /F /PID $pid > NUL");
|
exec("taskkill.exe /F " . ($subprocesses ? "/T " : "") . "/PID $pid");
|
||||||
break;
|
break;
|
||||||
case Utils::OS_MACOS:
|
case Utils::OS_MACOS:
|
||||||
case Utils::OS_LINUX:
|
case Utils::OS_LINUX:
|
||||||
default:
|
default:
|
||||||
|
if($subprocesses){
|
||||||
|
$pid = -$pid;
|
||||||
|
}
|
||||||
if(function_exists("posix_kill")){
|
if(function_exists("posix_kill")){
|
||||||
posix_kill($pid, 9); //SIGKILL
|
posix_kill($pid, 9); //SIGKILL
|
||||||
}else{
|
}else{
|
||||||
|
@ -50,7 +50,7 @@ class ServerKiller extends Thread{
|
|||||||
});
|
});
|
||||||
if(time() - $start >= $this->time){
|
if(time() - $start >= $this->time){
|
||||||
echo "\nTook too long to stop, server was killed forcefully!\n";
|
echo "\nTook too long to stop, server was killed forcefully!\n";
|
||||||
@Process::kill(Process::pid());
|
@Process::kill(Process::pid(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user