How to Kill a port using bash terminal command?

If you have a service running on your system on a certain port and you want to kill it using bash you can make use of the kill command, the kill command can send a signal to a process to terminate it,


Say I have MySQL running on port 3306 or tomcat on 8080 and I want to kill it,

$ kill $(lsof -t -i:3306)
$ kill $(lsof -t -i:8080)

lsof: list open files

-t: to produce an output of lsof without headers with just the process identifier (PID)

Kill a Port
Kill a Port

Have Questions? Post them here!

Recent Posts:

Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.