Last active
February 23, 2019 15:03
-
-
Save dominikkaegi/b0d2e7e2c509a38293c29a9a979fd421 to your computer and use it in GitHub Desktop.
Utilities function to find and kill a process on a port easily
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Implemented and tested on MacOS | |
| # Add utilties to ~./bash_profile to make them usable in your terminal | |
| # ------------------- PORT UTILTIES ---------------------- | |
| # Find PID of process on a specific port | |
| # param portNumber | |
| # example: "findPortProcess 8080" | |
| findPortProcess() { | |
| portProcess="$(lsof -n -i4TCP:$1 | grep LISTEN)" | |
| if [ "$portProcess" ] | |
| then | |
| echo $portProcess | |
| else | |
| echo "No Process on Port:$1" | |
| fi | |
| } | |
| # Kills Process on a Port | |
| # param portNumber | |
| # example: "killPort 8080" | |
| killPort() { | |
| processPID="$(lsof -ti tcp:$1)" | |
| if [ "$processPID" ] | |
| then | |
| kill $processPID | |
| echo "Killed Process on Port:$1" | |
| else | |
| echo "No Process on Port:$1" | |
| fi | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment