How to kill service running on a port on Ubuntu Linux


If you have a service running on a port on your Ubuntu Linux Server and want to kill it, you can achieve it by using the kill command,



Step 1: Identify the service running and get its Process Id (PID)

Syntax: sudo lsof -I:{PORT}
# sudo lsof -i:80

COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   2785 root    6u  IPv4  39198      0t0  TCP *:89 (LISTEN)
nginx   2785 root    7u  IPv6  39199      0t0  TCP *:80 (LISTEN)

As you can see I have made use of lsof command to see if I have my Nginx localhost server running on the device



Step 2: Kill the Service on the port using PID

Syntax: kill -9 {PID}
kill -9 2785


Kill the service in one single line

sudo kill -9 $(sudo lsof -t -I:{PORT})
Advertisements
Try Out Code2care Dev Tools:

Advertisements



#Android #Java #Linux #Microsoft #Google #Python #MacOS #Notepad++ #Microsoft Teams #CSS #PHP #SharePoint #Html #Linux #C-Program #Bootstrap #jQuery #Sublime #Android-Studio #Facebook #Eclipse #WhatsApp #News #MySQL #Json #HowTos #JavaScript #FTP #S3


Advertisements


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, Tutorials, Trouble-Shooting steps, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.
🎉 We are celebrating the 10th years of Code2care! Thank you for all your support! We hope we made a difference.
We strong support Gender Equality & Diversity.

We stand in solidarity with Ukraine - Make a donation to UNHCR - https://donate.unhcr.org/in/en-in/ukraine-emergency