How to Find the Process Using a Specific Port in Ubuntu Using lsof

The Port Conflict Problem

When you attempt to start a new web service on an Ubuntu Linux server, such as a local testing environment for Node.js or a fresh installation of Apache, the service will often instantly crash with a fatal error: “Address already in use: 0.0.0.0:80.” This simply means another program is already actively listening on port 80, preventing your new application from binding to it. To fix this, you cannot just delete files; you must identify exactly which background service is currently holding that port hostage and terminate its specific Process ID (PID).

Using the lsof Command

While you can use networking tools like netstat or ss to find this information, the “list open files” (lsof) command is much faster and more direct because Linux treats network sockets exactly like open files.

  1. Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
  2. Ensure the lsof utility is installed by typing sudo apt install lsof.
  3. To find the exact process using port 80, type the following command:
  4. sudo lsof -i :80
  5. Press Enter and provide your administrator password.

Understanding the Output and Killing the Process

The terminal will print a clear table. Look at the very first column (COMMAND) to see the name of the software (e.g., nginx or python3). The second column (PID) contains the critical numerical Process ID you need (e.g., 1452).

Once you have identified that the rogue process is an old, forgotten Python script running on PID 1452, you can terminate it instantly:

  1. Type sudo kill -9 1452 (replace 1452 with your actual PID).
  2. Press Enter.

The -9 flag sends an absolute kill signal, instantly freeing the port so you can start your new web service without conflict.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.