Skip to content

Instantly share code, notes, and snippets.

@SalemCode8
Last active August 16, 2018 21:42
Show Gist options
  • Select an option

  • Save SalemCode8/62ee3194708e4a4349017c0dd3592227 to your computer and use it in GitHub Desktop.

Select an option

Save SalemCode8/62ee3194708e4a4349017c0dd3592227 to your computer and use it in GitHub Desktop.
Kill Process Running On Port
#!/bin/sh
# Author: Salem Code <salemode8@gmail.com>
if [ -z "$1" ]
then
echo "\e[41mPort Number is Required\e[0m"
exit
fi
PORT="$(lsof -i :$1 | awk '{print $2 }')"
if [ -z "$PORT" ]
then
echo "\e[42mPort is Not In Use\e[0m"
exit
fi
kill $(echo $PORT | grep -oP "\d+")
echo "\e[42;1mProcess Killed Successfully\e[0m"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment