How to kill a process on a port on ubuntu

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

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

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

    Use killport command :

    sh killport 9001 
    

    To Download shell ,you can use wget :

    wget https://cdn.rawgit.com/abdennour/miscs.sh/e0aac343/killport
    
    0 讨论(0)
  • 2020-12-02 03:59

    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.

    0 讨论(0)
  • 2020-12-02 04:01

    you can work this using node

    npm install freethenport -g
    

    then

    node freethenport 9001
    
    0 讨论(0)
  • 2020-12-02 04:02

    Displays active TCP connections, ports on which the computer is listening.

    netstat -tupln
    

    It will list you all the connection along pid. Find and copy the pid and run the following command. Make sure you replace the with actual id in the following command.

    kill -9 <copied pid>
    

    -9 use to forcefully kill the connection.

    0 讨论(0)
  • 2020-12-02 04:06

    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

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