Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to kill a process running on particular port in Linux?

I tried to close the tomcat using ./shutdown.sh from tomcat /bin directory. But found that the server was not closed properly. And thus I was unable to restart
My tomcat is running on port 8080.

I want to kill the tomcat process running on 8080. I first want to have the list of processes running on a specific port (8080) in order to select which process to kill.

like image 939
veer7 Avatar asked Jul 20 '12 16:07

veer7


3 Answers

This fuser 8080/tcp will print you PID of process bound on that port.

And this fuser -k 8080/tcp will kill that process.

Works on Linux only. More universal is use of lsof -i4 (or 6 for IPv6).

like image 95
nudzo Avatar answered Nov 20 '22 13:11

nudzo


To list any process listening to the port 8080:

lsof -i:8080

To kill any process listening to the port 8080:

kill $(lsof -t -i:8080)

or more violently:

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

(-9 corresponds to the SIGKILL - terminate immediately/hard kill signal: see List of Kill Signals and What is the purpose of the -9 option in the kill command?. If no signal is specified to kill, the TERM signal a.k.a. -15 or soft kill is sent, which sometimes isn't enough to kill a process.).

like image 31
Franck Dernoncourt Avatar answered Nov 20 '22 13:11

Franck Dernoncourt


Use the command

 sudo netstat -plten |grep java

used grep java as tomcat uses java as their processes.

It will show the list of processes with port number and process id

tcp6       0      0 :::8080                 :::*                    LISTEN      
1000       30070621    16085/java

the number before /java is a process id. Now use kill command to kill the process

kill -9 16085

-9 implies the process will be killed forcefully.

like image 365
veer7 Avatar answered Nov 20 '22 15:11

veer7