Search code examples
terminalportosx-maverickskill

Kill all processes running on port 8080 on Mavericks


I'm getting a "socket.error: No socket could be created" when running a web.py script.

Is there a way to kill all processes on running on port 8080 (or any other port I wish) with a single line in Terminal on OSX Mavericks?


Solution

  • It's a single line, but you'd need to put it into a shell alias or shell script in order to make it easy to use:

    $ kill $(lsof -i tcp:8080 | tail -n +2 | awk '{ print $2 }')
    

    If you want to see and kill processes that don't belong to you, then sudo needs to get involved:

    $ sudo kill $(sudo lsof -i tcp:8080 | tail -n +2 | awk '{ print $2 }')