How to kill a process on a port on ubuntu

2019-01-12 13:16发布

问题:

I am trying to kill a proccess in the command line for a specific port in ubuntu.

If I run this command I get the port:

sudo lsof -t -i:9001

so...now I want to run:

sudo kill 'sudo lsof -t -i:9001'

I get this error message:

ERROR: garbage process ID "lsof -t -i:9001".
Usage:
  kill pid ...              Send SIGTERM to every process listed.
  kill signal pid ...       Send a signal to every process listed.
  kill -s signal pid ...    Send a signal to every process listed.
  kill -l                   List all signal names.
  kill -L                   List all signal names in a nice table.
  kill -l signal            Convert between signal numbers and names.

I tried sudo kill 'lsof -t -i:9001' as well

回答1:

You want to use backtick not regular tick:

sudo kill `sudo lsof -t -i:9001`

If that doesn't work you could also use $() for command interpolation:

sudo kill $(sudo lsof -t -i:9001)


回答2:

you can use

fuser -n tcp -k 9001 

see more details in wikipedia



回答3:

FOR UBUNTU 1- Find what application/process is using the pro, type:

sudo netstat -lpn |grep :8080

and press Enter.

You will get an output similar to this one

tcp6       0      0 :::8080                 :::*                    LISTEN      6782/java

2- I have got the process Id, which is 6782, now this is the process that is using port 8080.

3- Kill the process, type:kill 6782

kill 6782


回答4:

There are some process which does not shown using normal netstat command, so you have to check it using sudo.

Do sudo netstat -lpn |grep :8080. Process running by system does not show PID, to get PID of this process you will have to run it using sudo

And then killl the process using port 8080. You may have to use sudo here as well. So to kill this process use sudo kill -9 PID



回答5:

The best way to kill a port in ubuntu terminal is fuser -k 9001/tcp



回答6:

Use killport command :

sh killport 9001 

To Download shell ,you can use wget :

wget https://cdn.rawgit.com/abdennour/miscs.sh/e0aac343/killport


回答7:

You may also use fuser to do that (sends SIGKILL by default): sudo fuser -k 9001/tcp



回答8:

Use this:

sudo kill -9 $(lsof -t -i:9001)


回答9:

To kill a Process running on port number 9001

sudo kill -9 $(sudo lsof -t -i:9001)


lsof   - list of files(Also used for to list related processes)

-t     - show only process ID

-i     - show only internet connections related process

:9001  - show only processes in this port number

kill   - command to kill the process

-9     - forcefully

sudo   - command to ask admin privilege(user id and password).

for more you can visit my blog



回答10:

To kill the process based on port first we have to find out the relevant pid for given port and kill using that pid,

In my case i wanted to get the pid(process id) of 3000 port:

netstat -ltnp | grep -w '3000'

then find pid which is listening to tcp

tcp6       0      0 :::3000                 :::*                    LISTEN      29972/node  

you will get pid 29972

To kill this pid use below command

kill -9 26493

pseudo code for kill process based on port

 netstat -ltnp | grep -w 'PORT'

and

kill -9 PID


回答11:

Kill PORT:

sudo is important to show process id.

$ sudo netstat -antlp | grep 45136
tcp      0      0 0.0.0.0:45136         0.0.0.0:*        LISTEN           **-** 

$ kill -9 45136


回答12:

Use this for killing process which is running on port number "9001"

 kill $(lsof -t -i:9001)


回答13:

Try this:

lsof -i :port

or 

sudo kill $(sudo lsof -t -i:8000)

or

kill -9 <pid>

or 

sh killport 8000


回答14:

Use the command

 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.



回答15:

sudo kill `sudo lsof -t -i:9001`

you don't have to add the -9signal option



回答16:

Its two steps process:

  1. Know process id on port no. 8080 (can be any)
  2. Kill process of that id 8689 (can be different)

    fuser -n tcp 8080
    
    #o/p 8080/tcp    8689
    
    kill -9 8689
    


回答17:

sudo kill $(sudo lsof -t -i:1337)



回答18:

you can work this using node

npm install freethenport -g

then

node freethenport 9001


回答19:

To kill on port service in ubuntu, Enter the below command in terminal

In Terminal :

sudo fuser -k port/tcp
sudo fuser -k 8001/tcp


标签: ubuntu port kill