Skip to content

Instantly share code, notes, and snippets.

@andrewriveradev
Last active March 16, 2023 03:08
Show Gist options
  • Save andrewriveradev/6fa70a3fb9247c47c6d1f413d3014047 to your computer and use it in GitHub Desktop.
Save andrewriveradev/6fa70a3fb9247c47c6d1f413d3014047 to your computer and use it in GitHub Desktop.

Revisions

  1. andrewriveradev revised this gist Mar 16, 2023. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions killport.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,8 @@
    #!/bin/bash
    # Context:
    # - add killport.sh to path export PATH="$HOME/bin:$PATH" assuming $HOME/bin is where you keep your scripts
    # - make killport.sh executable chmod +x killport.sh

    # write the command to kill the process running on the port
    kill -9 $(lsof -t -i:$1)
    # write command to notify the user that the process has been killed or not
  2. andrewriveradev created this gist Mar 16, 2023.
    10 changes: 10 additions & 0 deletions killport.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    #!/bin/bash
    # write the command to kill the process running on the port
    kill -9 $(lsof -t -i:$1)
    # write command to notify the user that the process has been killed or not
    if [ $? -eq 0 ]
    then
    echo "Process running on port $port has been killed"
    else
    echo "No process running on port $port"
    fi