Skip to content

Instantly share code, notes, and snippets.

@telmofcosta
Created November 30, 2012 11:22
Show Gist options
  • Save telmofcosta/4175203 to your computer and use it in GitHub Desktop.
Save telmofcosta/4175203 to your computer and use it in GitHub Desktop.
kill process running on some port
#!/bin/bash
PORT=$1
if [ -n "$PORT" ]; then
LINE=$(lsof -i tcp -n -P | grep ":$PORT (LISTEN)")
if [ -n "$LINE" ]; then
echo $LINE
PID=$(echo $LINE | awk '{print $2}')
fi
if [ -n "$PID" ]; then
echo "kill -9 $PID"
kill -9 $PID
else
echo "no pid on port $PORT" >&2
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment