
This happens constantly in real sysadmin work. You restart a service, get Address already in use, and now you’re digging through process lists trying to figure out what’s squatting on your port.
The fix is straightforward once you know the right commands, and there are 3 solid ways to do it depending on what tools you have available on your system.
Find What’s Running on a Port First
Before you kill anything, you need to know what process owns the port. Guessing and killing random processes is how you break things in production. So run one of these first.
lsof is the most common tool for this and it’s available on almost every Linux system by default.
sudo lsof -i :8080
The sudo here runs the command with root privileges so lsof can see processes owned by other users, not just your own. Without it, you’ll only see processes running as your current user, which is usually not what you want.
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME node 3821 ravi 22u IPv6 54312 0t0 TCP *:8080 (LISTEN)
That output tells you everything. node is the process name, 3821 is the PID you’ll use to kill it, and LISTEN confirms it’s actively holding the port open. If you see ESTABLISHED instead, the process has an active connection through that port.
If lsof isn’t installed, use ss command, which is part of the iproute2 package and available on essentially every modern Linux system.
sudo ss -tulnp | grep :8080
Here’s what each flag does:
-t– show TCP sockets-u– show UDP sockets-l– show only listening sockets-n– show port numbers instead of service names-p– show the process using the socket
tcp LISTEN 0 128 0.0.0.0:8080 0.0.0.0:* users:(("node",pid=3821,fd=22))
The pid=3821 at the end is what you’re after. Same process, same PID, just a different tool to find it.
Kill It with the kill Command
Once you have the PID, kill command is the direct approach. By default it sends SIGTERM (signal 15), which asks the process to shut down cleanly and flush any open file handles or connections before exiting.
kill 3821
No output means it worked. Run lsof -i :8080 again to confirm.
lsof -i :8080
If the process ignores SIGTERM and the port is still occupied after a few seconds, force it with SIGKILL (signal 9), which terminates the process immediately without giving it a chance to clean up.
kill -9 3821
Warning: SIGKILL can’t be caught or blocked by the process, so it works every time, but it also means the process has no chance to write pending data to disk or close database connections cleanly. Use it as a last resort, not a first move.
Kill It Directly with fuser
The fuser command skips the two-step approach entirely. You give it the port number and it kills whatever’s using it, no PID lookup required.
sudo fuser -k 8080/tcp
-k– send SIGTERM to every process using that port.8080/tcp– the port and protocol you’re targeting.
8080/tcp: 3821
fuser prints the PID it killed and exits. That’s it. If you want SIGKILL instead of SIGTERM, add -9:
sudo fuser -k -9 8080/tcp
Note: fuser may not be installed by default on minimal server installs, so install it as shown.
sudo apt install psmisc [On Debian, Ubuntu and Mint] sudo dnf install psmisc [On RHEL/CentOS/Fedora and Rocky/AlmaLinux]
ps aux | grep session, who’s still doing it the long way.Kill It with a One-Liner Using lsof and kill Together
If you want to skip the manual PID lookup and kill in a single command, combine lsof and kill with command substitution.
sudo kill -9 $(sudo lsof -t -i :8080)
Here’s what each part does:
lsof -t -i :8080the-tflag outputs only the PID, nothing else, so you get a clean number to pass to kill$(...)– command substitution, runs the inner command and passes its output as an argument.kill -9– sends SIGKILL to whatever PID lsof returns.
If the port comes back empty after running that, the process is gone and the port is free. If you get kill: usage or a syntax error, the port was already free and lsof returned nothing, so kill had nothing to work with.
Tip: If multiple processes are sharing the same port (rare, but it happens with SO_REUSEPORT), this one-liner kills all of them at once because lsof -t can return multiple PIDs on separate lines.
Conclusion
You’ve got 3 working approaches now: lsof or ss to identify the PID, kill to terminate it by PID, fuser to kill by port directly, and the lsof + kill one-liner for when you want it done in a single command.
The one thing to try right now: spin up any service on port 8080 (python3 -m http.server 8080 works if you have Python installed), then run sudo lsof -i :8080, grab the PID, and kill it. Do it a few times and the muscle memory will stick faster than any bookmark.
What’s the worst port conflict you’ve dealt with in production? Something holding a database port hostage, or a zombie process that wouldn’t die? Drop it in the comments.
