How to kill a process on a port on ubuntu

前端 未结 27 2226
天涯浪人
天涯浪人 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:46

    just enter

        fuser -k -n tcp 3000
    

    in terminal , where 3000 is your port number

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

    Use this:

    sudo kill -9 $(lsof -t -i:9001)
    
    0 讨论(0)
  • 2020-12-02 03:47

    If I was you,I would use

    fuser -k -n tcp PORT
    kill -9 PID
    
    0 讨论(0)
  • 2020-12-02 03:49

    the below command will kill your running port

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

    you can use

    fuser -n tcp -k 9001 
    

    see more details in wikipedia

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

    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 29972
    

    pseudo code for kill process based on port

     netstat -ltnp | grep -w 'PORT'
    

    and

    kill -9 PID
    
    0 讨论(0)
提交回复
热议问题