Skip to content

Instantly share code, notes, and snippets.

@ncherro
Created January 15, 2013 15:53
Show Gist options
  • Save ncherro/4539635 to your computer and use it in GitHub Desktop.
Save ncherro/4539635 to your computer and use it in GitHub Desktop.
Kill a process on a port. Defaults to 3000 (Rails)
killport() {
if [ -n "${1}" ]; then
port=$1
else
# default (Rails-centric)
port="3000"
fi
pid=`lsof -wni tcp:$port | awk 'NR==2 { print $2 }'`
if [ -n "${pid}" ]; then
kill -9 $pid
echo "Killed process $pid"
else
echo "No processes were found listening on tcp:$port"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment