DEV Community

Olaniyi Philip Ojeyinka
Olaniyi Philip Ojeyinka

Posted on • Edited on

2

create an alias to force Kill a port

add to your bash_profile, or bashrc file etc.


port_kill() {
    if [ -z "$1" ]; then
        echo "Usage: port_kill PORT_NUMBER"
        return 1
    fi

    PIDs=$(lsof -t -i :"$1" 2>/dev/null)
    if [ -n "$PIDs" ]; then
        kill -9 $PIDs 2>/dev/null
        echo "✓ Successfully killed process(es) running on port $1"
        return 0
    else
        echo "No process running on port $1"
        return 1
    fi
}
alias force-kill='port_kill'

Enter fullscreen mode Exit fullscreen mode

usage

force-kill 3000
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay