killport() {
    if [[ $# -eq 0 ]]; then
        echo "Usage: killport <port>"
        return 1
    fi
    local port=$1
    local pid=$(lsof -n -i4TCP:"$port" | awk 'NR>1 {print $2}')
    if [[ -n $pid ]]; then
        kill -9 "$pid"
        echo "Process with PID $pid killed."
    else
        echo "No process found running on port $port."
    fi
}
Add this to .zshrc
Call killport 8080 from terminal.
              
    
Top comments (0)