Skip to content

Instantly share code, notes, and snippets.

@marcosvidolin
Last active June 8, 2021 10:34
Show Gist options
  • Star 29 You must be signed in to star a gist
  • Fork 16 You must be signed in to fork a gist
  • Save marcosvidolin/df5debc68e45314780a8 to your computer and use it in GitHub Desktop.
Save marcosvidolin/df5debc68e45314780a8 to your computer and use it in GitHub Desktop.
Linux: How to list and kill a process using a port
# to list all ports that are used
sudo netstat -ntlp | grep LISTEN
# you can obtain a specific port using the following command
sudo netstat -ntlp | grep :8080
# when you execute the command above you will see something like that
tcp 0 0 0.0.0.0:27370 0.0.0.0:* LISTEN 4394/skype
tcp 0 0 127.0.1.1:53 0.0.0.0:* LISTEN 2216/dnsmasq
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 4912/cupsd
tcp6 0 0 :::8080 :::* LISTEN 8868/java
tcp6 0 0 ::1:631 :::* LISTEN 4912/cupsd
# to kill the process using the port 8080 see the process number "8868/java" then:
sudo kill -TERM 8868
@alicelebidev
Copy link

Thanks for sharing this!

@devils-ey3
Copy link

Thanks dude

@higormarques
Copy link

Thanks man!

@tiendv-1114
Copy link

thanks for help me! 👍

@jontreynes
Copy link

how should I kill a process that doesn't have a unique TERM?
for ex.

netstat -ntlp | grep :8301
(No info could be read for "-p": geteuid()=1000 but you should be root.)
tcp6 0 0 :::8301 :::* LISTEN -

@tunglam14
Copy link

fuser -k -TERM 8080/tcp

@bkbatchelor
Copy link

netstat is being replace with 'ss'

$ ss -nlp | grep 9229

tcp LISTEN 0 128 127.0.0.1:9229
users:(("node",pid=14191,fd=22))

$ kill 14191

@backent
Copy link

backent commented Nov 23, 2018

Thanks dude

@hari42511
Copy link

Thanks a lot. Its workout.........

@Aragami1408
Copy link

You saved my day

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment