Skip to content

Instantly share code, notes, and snippets.

@andrewn
Created May 16, 2022
Embed
What would you like to do?
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