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 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 result = await Cli.Wrap(Global.LinuxBash)
.WithArguments(arg)

View File

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