use lsof for ports
This commit is contained in:
parent
7bf03c3ab7
commit
104d77724a
1 changed files with 1 additions and 7 deletions
|
|
@ -22,11 +22,5 @@ find_available_port() {
|
||||||
# @return 0 if the port is available, 1 otherwise.
|
# @return 0 if the port is available, 1 otherwise.
|
||||||
is_port_available() {
|
is_port_available() {
|
||||||
local port=$1
|
local port=$1
|
||||||
if [[ "$OS" == "Mac" ]]; then
|
! lsof -iTCP:"$port" -sTCP:LISTEN -P -t >/dev/null 2>&1
|
||||||
# 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
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue