Update util.sh

amend shell get pid command fd on mac.
pull/1745/head
mrwenhui 2 years ago committed by GitHub
parent 960d51eda0
commit e0ba585f5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -310,8 +310,8 @@ openim::util::check_ports() {
info=$(netstat -ltnp | grep ":$port" || true) info=$(netstat -ltnp | grep ":$port" || true)
fi fi
elif [[ "$OSTYPE" == "darwin"* ]]; then elif [[ "$OSTYPE" == "darwin"* ]]; then
# For macOS, use netstat # For macOS, use lsof
info=$(netstat -an -p tcp | grep "\.$port " || true) info=$(lsof -i:"$port" | grep "\*:$port" || true)
fi fi
# Check if any process is using the port # Check if any process is using the port
@ -326,9 +326,9 @@ openim::util::check_ports() {
fd=$(echo $details | awk '{print $3}') fd=$(echo $details | awk '{print $3}')
elif [[ "$OSTYPE" == "darwin"* ]]; then elif [[ "$OSTYPE" == "darwin"* ]]; then
# Handle extraction for macOS # Handle extraction for macOS
pid=$(echo $info | awk '{print $9}' | cut -d'/' -f1) pid=$(echo $info | awk '{print $2}' | cut -d'/' -f1)
command=$(ps -p $pid -o comm=) command=$(ps -p $pid -o comm= | xargs basename)
fd="N/A" # File Descriptor is not available in macOS netstat output fd=$(echo $info | awk '{print $4}' | cut -d'/' -f1)
fi fi
# Get the start time of the process using the PID # Get the start time of the process using the PID
@ -1407,4 +1407,4 @@ function openim::util::gen_os_arch() {
if [[ "$*" =~ openim::util:: ]];then if [[ "$*" =~ openim::util:: ]];then
eval $* eval $*
fi fi

Loading…
Cancel
Save