Fixed bug for macos kill_as_sudo

pull/7673/head
2dust 2025-07-30 20:33:51 +08:00
parent 3d23f3e3a2
commit 8662d94ab6
2 changed files with 9 additions and 6 deletions

View File

@ -96,7 +96,10 @@ public class CoreAdminHandler
{ {
var shellFileName = Utils.IsOSX() ? Global.KillAsSudoOSXShellFileName : Global.KillAsSudoLinuxShellFileName; var shellFileName = Utils.IsOSX() ? Global.KillAsSudoOSXShellFileName : Global.KillAsSudoLinuxShellFileName;
var shFilePath = await FileManager.CreateLinuxShellFile("kill_as_sudo.sh", EmbedUtils.GetEmbedText(shellFileName), true); var shFilePath = await FileManager.CreateLinuxShellFile("kill_as_sudo.sh", EmbedUtils.GetEmbedText(shellFileName), true);
if (shFilePath.Contains(' '))
{
shFilePath = shFilePath.AppendQuotes();
}
var arg = new List<string>() { "-c", $"sudo -S {shFilePath} {_linuxSudoPid}" }; var arg = new List<string>() { "-c", $"sudo -S {shFilePath} {_linuxSudoPid}" };
var result = await Cli.Wrap(Global.LinuxBash) var result = await Cli.Wrap(Global.LinuxBash)
.WithArguments(arg) .WithArguments(arg)

View File

@ -18,8 +18,8 @@ if ! [[ "$PID" =~ ^[0-9]+$ ]]; then
exit 1 exit 1
fi fi
# Check if the process exists # Check if the process exists - using kill -0 which is more reliable on macOS
if ! ps -p $PID > /dev/null; then if ! kill -0 $PID 2>/dev/null; then
echo "Warning: No process found with PID $PID" echo "Warning: No process found with PID $PID"
exit 0 exit 0
fi fi
@ -27,8 +27,8 @@ fi
# Recursive function to find and kill all descendant processes # Recursive function to find and kill all descendant processes
kill_descendants() { kill_descendants() {
local parent=$1 local parent=$1
# Use ps -eo pid,ppid for macOS compatibility # Use ps -axo for macOS to ensure all processes are included
local children=$(ps -eo pid=,ppid= | awk -v ppid=$parent '$2==ppid {print $1}') local children=$(ps -axo pid=,ppid= | awk -v ppid=$parent '$2==ppid {print $1}')
echo "Processing children of PID: $parent..." echo "Processing children of PID: $parent..."
for child in $children; do for child in $children; do