How to kill a process on a port on ubuntu

前端 未结 27 2225
天涯浪人
天涯浪人 2020-12-02 03:05

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

If I run this command I get the port:

sudo lsof -t -i:9001


        
相关标签:
27条回答
  • 2020-12-02 03:41

    sudo fuser -n tcp -k [port_number]

    sudo lsof -t -i:[port_number]

    0 讨论(0)
  • 2020-12-02 03:42

    It gives me an error OSError: [Errno 98] Address already in use. using the following method solved my error in Ubuntu.(VERSION="18.04.4 LTS (Bionic Beaver)")

    $ sudo netstat -lpn |grep :5000
    tcp        0      0 0.0.0.0:5000            0.0.0.0:*               LISTEN      25959/uwsgi   
    
    $ fuser -k -n tcp 5000
    5000/tcp:            25959
     
    

    Hope it will help someone!

    0 讨论(0)
  • 2020-12-02 03:43

    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
    
    0 讨论(0)
  • 2020-12-02 03:43

    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

    0 讨论(0)
  • 2020-12-02 03:45
    sudo kill `sudo lsof -t -i:9001`
    

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

    0 讨论(0)
  • 2020-12-02 03:45

    Try sudo fuser PORT/tcp -k Replace PORT with the port you want to kill, for example 80

    0 讨论(0)
提交回复
热议问题