mirror of
https://github.com/2dust/v2rayN.git
synced 2026-10-18 03:05:00 +03:00
Fixed bug for macos kill_as_sudo
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user