Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion v2rayN/ServiceLib/Manager/CoreAdminManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private async Task UpdateFunc(bool notify, string msg)
StringBuilder sb = new();
sb.AppendLine("#!/bin/bash");
var cmdLine = $"{fileName.AppendQuotes()} {string.Format(coreInfo.Arguments, Utils.GetBinConfigPath(configPath).AppendQuotes())}";
sb.AppendLine($"sudo -S {cmdLine}");
sb.AppendLine($"exec sudo -S -- {cmdLine}");
var shFilePath = await FileManager.CreateLinuxShellFile("run_as_sudo.sh", sb.ToString(), true);

var procService = new ProcessService(
Expand Down
18 changes: 15 additions & 3 deletions v2rayN/ServiceLib/Sample/kill_as_sudo_linux_sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ fi
kill_children() {
local parent=$1
local children=$(ps -o pid --no-headers --ppid "$parent")

# Output information about processes being terminated
echo "Processing children of PID: $parent..."

# Process each child
for child in $children; do
# Recursively find and kill child's children first
kill_children "$child"

# Force kill the child process
echo "Terminating child process: $child"
kill -9 "$child" 2>/dev/null || true
Expand All @@ -47,6 +47,18 @@ echo "============================================"
echo "Starting termination of process $PID and all its children"
echo "============================================"

# Try graceful termination first
echo "Attempting graceful termination (SIGTERM) of PID: $PID"
kill -15 "$PID" 2>/dev/null || true
sleep 1
# If still running, fall back to kill_children
if ps -p $PID > /dev/null; then
echo "Process $PID did not exit after SIGTERM; proceeding with forced termination of its children and itself"
else
echo "Process $PID exited cleanly after SIGTERM"
exit 0
fi

# Find and kill all child processes
kill_children "$PID"

Expand Down
14 changes: 14 additions & 0 deletions v2rayN/ServiceLib/Sample/kill_as_sudo_osx_sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ echo "============================================"
echo "Starting termination of process $PID and all its descendants"
echo "============================================"

# Try graceful termination first
echo "Attempting graceful termination (SIGTERM) of PID: $PID"
kill -15 "$PID" 2>/dev/null || true
sleep 1

# If still running, fall back to kill_descendants
# Use the macOS-native 'kill -0' check
if kill -0 $PID 2>/dev/null; then
echo "Process $PID did not exit after SIGTERM; proceeding with forced termination of its descendants and itself"
else
echo "Process $PID exited cleanly after SIGTERM"
exit 0
fi

# Find and kill all descendant processes
kill_descendants "$PID"

Expand Down