← Catalog Matrix
DevOps

How to Find and Kill Processes on Specific Ports Linux/macOS

A collection of terminal command scripts to identify which application is locking a network port and force kill it instantly.

Overview & Problem Matrix

When launching local web development environments, database microservices, or backend API frameworks, you will frequently encounter fatal runtime exceptions like EADDRINUSE: address already in use :::8080.

This system collision occurs because a rogue background process, crashed service worker, or previously unclosed daemon did not terminate cleanly and is still locking down that specific network socket. You need a fast, zero-dependency terminal mechanism to identify the offending Process ID (PID) and release the interface constraints immediately.

Implementation Guide & Setup Steps

To identify and terminate conflicting network processes across your environments, execute these terminal operations:

  1. Open Your Operational Console: Launch your local terminal instance or establish a secure remote network session via SSH with your host node:

$ ssh user@your-server-ip

  1. Method 1 - Standard Audit Pipeline (macOS & Linux): Query the system files list to identify the exact application name and Process ID (PID) occupying your target port (e.g., port 8080):

$ lsof -i :8080

# Terminate the rogue PID using a strict force-kill flag: $ kill -9 <PID_NUMBER>

  1. Method 2 - Combined One-Liner Execution: To automatically locate and force-kill any process blocking port 8080 without manual steps, pipe the layout to a safe execution string.

# NOTE: Appending "xargs -r" ensures that if the port is already empty, the command closes quietly instead of throwing usage errors: $ lsof -t -i:8080 | xargs -r kill -9

  1. Method 3 - Linux Native Alternative (fuser): If your specific Linux distribution lacks the lsof package, deploy the native kernel tool to force-release your target TCP socket instantly:

$ fuser -k 8080/tcp

  1. Elevate Privileges When Necessary: If the target port is bound to a system service or root daemon, append your administrative overrides to ensure complete execution clearance:

$ sudo lsof -t -i:8080 | xargs sudo kill -9

Option A: Using lsof (Recommended for macOS and Linux)

To find out exactly what program is running on a port (e.g., port 8080), execute this mapping filter: lsof -i :8080

Once you identify the Process ID (PID) from the console output grid, force kill it using the kill utility: kill -9 <PID_NUMBER>

The One-Liner Shortcut: You can combine these commands to find and kill whatever is occupying port 8080 in a single step: kill -9 $(lsof -t -i:8080)

Option B: Using fuser (Native Linux / Ubuntu Systems)

If your Linux distribution does not have lsof pre-installed, you can use the native fuser tool to accomplish the same result.

To automatically kill any TCP protocol process using port 8080 without manual confirmations, run: fuser -k 8080/tcp