This content originally appeared on DEV Community and was authored by Olaniyi Philip Ojeyinka
add to your bash_profile, or basrc 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'
This content originally appeared on DEV Community and was authored by Olaniyi Philip Ojeyinka
Print
Share
Comment
Cite
Upload
Translate
Updates
There are no updates yet.
Click the Upload button above to add an update.

APA
MLA
Olaniyi Philip Ojeyinka | Sciencx (2025-02-22T16:05:02+00:00) create an alias to force Kill a port. Retrieved from https://www.scien.cx/2025/02/22/create-an-alias-to-force-kill-a-port/
" » create an alias to force Kill a port." Olaniyi Philip Ojeyinka | Sciencx - Saturday February 22, 2025, https://www.scien.cx/2025/02/22/create-an-alias-to-force-kill-a-port/
HARVARDOlaniyi Philip Ojeyinka | Sciencx Saturday February 22, 2025 » create an alias to force Kill a port., viewed ,<https://www.scien.cx/2025/02/22/create-an-alias-to-force-kill-a-port/>
VANCOUVEROlaniyi Philip Ojeyinka | Sciencx - » create an alias to force Kill a port. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/02/22/create-an-alias-to-force-kill-a-port/
CHICAGO" » create an alias to force Kill a port." Olaniyi Philip Ojeyinka | Sciencx - Accessed . https://www.scien.cx/2025/02/22/create-an-alias-to-force-kill-a-port/
IEEE" » create an alias to force Kill a port." Olaniyi Philip Ojeyinka | Sciencx [Online]. Available: https://www.scien.cx/2025/02/22/create-an-alias-to-force-kill-a-port/. [Accessed: ]
rf:citation » create an alias to force Kill a port | Olaniyi Philip Ojeyinka | Sciencx | https://www.scien.cx/2025/02/22/create-an-alias-to-force-kill-a-port/ |
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.