use lsof for ports

This commit is contained in:
shocknet-justin 2025-09-25 12:46:15 -04:00
parent 7bf03c3ab7
commit 104d77724a

View file

@ -22,11 +22,5 @@ find_available_port() {
# @return 0 if the port is available, 1 otherwise.
is_port_available() {
local port=$1
if [[ "$OS" == "Mac" ]]; then
# Use lsof on macOS
! lsof -iTCP:"$port" -sTCP:LISTEN -P -t >/dev/null
else
# Use ss on Linux
! ss -lntu | awk '{print $5}' | grep -q ":$port$"
fi
! lsof -iTCP:"$port" -sTCP:LISTEN -P -t >/dev/null 2>&1
}