Skip to content
The Chat Archive
deepseek-v3-0324· DeepSeek LMArena Human Preference 140K

how to kill process in Linux which uses given port e.g. 5000

  1. User

    how to kill process in Linux which uses given port e.g. 5000

  2. Assistant

    To kill a process in Linux that is using a specific port (e.g., port 5000), follow these steps:

    1. Find the Process ID (PID) Using the Port

    Use the lsof (List Open Files) command to identify the process:

    sudo lsof -i :5000
    

    Example output:

    COMMAND   PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
    python3 12345     user    3u  IPv4 123456      0t0  TCP *:5000 (LISTEN)
    
    • The PID (e.g., 12345) is the process ID you need to kill.

    2. Kill the Process

    Once you have the PID, terminate it using:

    sudo kill -9 12345
    

    (Replace 12345 with the actual PID from the previous step.)

    Alternative: Using fuser

    You can also use fuser to find and kill the process:

    sudo fuser -k 5000/tcp
    

    This directly kills the process using port 5000.

    If lsof or fuser is Not Installed

    Install them using:

    • Debian/Ubuntu:
      sudo apt install lsof
      
    • RHEL/CentOS:
      sudo yum install lsof
      

    Verify the Port is Freed

    Check if the port is no longer in use:

    sudo lsof -i :5000
    

    (No output means the port is free.)

    This should successfully kill the process using port 5000. Let me know if you need further help! 🚀

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.