Created
May 16, 2022 12:12
-
-
Save andrewn/e5f4f88bc44cfcd9c875d41468c5d8a6 to your computer and use it in GitHub Desktop.
Find out what's using those local TCP ports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Kill process using the port | |
# Usage: kill-port <port-number> | |
# | |
# Example: | |
# $ kill-port 3000 | |
# Killed 🔪 | |
if [ $# -eq 0 ] | |
then | |
echo "No arguments supplied: specify port" | |
exit 1 | |
fi | |
pid=`lsof -i :$1 -t` | |
if [ -z "$pid" ] | |
then | |
echo "No pid for port $1" | |
exit 1 | |
fi | |
kill -HUP $pid | |
echo "Killed 🔪" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Which process is using the port? | |
# Usage: which-port <port-number> | |
# | |
# Example: | |
# $ which-port 3000 | |
# -+- 87504 andrew node /Users/a/Projects/thing/node_modules/.bin/vite | |
# \--- 87573 andrew /Users/a/Projects/personal/thing/node_modules/esbuild-darwin-64/bin/esbuild --service=0.14.38 --ping | |
if [ $# -eq 0 ] | |
then | |
echo "No arguments supplied: specify port" | |
exit 1 | |
fi | |
pid=`lsof -i :$1 -t` | |
if [ -z "$pid" ] | |
then | |
echo "No pid for port $1" | |
exit 1 | |
fi | |
pstree $pid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment