macos check if port is used code example
Example 1: netstat listening port 8080 mac
lsof -nP -iTCP:$PORT | grep LISTEN
Example 2: running ports in mac
sudo lsof -PiTCP -sTCP:LISTEN
lsof -nP -iTCP:$PORT | grep LISTEN
sudo lsof -PiTCP -sTCP:LISTEN