Monday, May 16, 2016

Automatically kill the process running on port $PORT in shell

Write this in a file and save it as filename.sh
Now, you can kill whatever process is running on the port you enter.
Note: this only works on *nix systems (lsof doesn't work in girt bash either).

     # kill the process using the desired port
     if [ -z "$1" ]
     then
       printf "Please select a port number to kill by, ie 8263:"
       read PORT
     else
       PORT=$1
     fi
     
     printf "\nThings running on port:$PORT\n==========================\n"
     STR=$(lsof -i:$PORT)
     if [ -z "$STR" ]
     then
       printf "Nothing was running\n"
     else
       printf "Killing process on port: $PORT\n==========================\n"
       kill -9 $(lsof -t -i:$PORT)
       lsof -i:$PORT
     fi
     
     read -p "Done. Press enter to continue..."

2 comments:

  1. Was not a lot of scientific evidence supporting that it could really help and sirIthink both of us just really kind of stayed away from it but we got sent this MaxedOut Male
    MaxedOut Male
    MaxedOut Male
    MaxedOut Male
    MaxedOut Male
    MaxedOut Male to try and Wow it is amazing you can mix it in with a serum you can mix it in with a moisturizer butIjust use it a learn off the toning and it's just so calming it's for soothing stressed.

    ReplyDelete