Skip to content

Instantly share code, notes, and snippets.

@andrewn
Created May 16, 2022 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewn/e5f4f88bc44cfcd9c875d41468c5d8a6 to your computer and use it in GitHub Desktop.
Save andrewn/e5f4f88bc44cfcd9c875d41468c5d8a6 to your computer and use it in GitHub Desktop.
Find out what's using those local TCP ports
#!/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 🔪"
#!/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