← back to latest

Find out which process is sitting on port 8080

lsof -nP -iTCP:8080 -sTCP:LISTEN

anatomy

lsof
List open files. On Unix a socket counts as a file, which is why a file tool answers network questions.
-n
Skip reverse DNS lookups. Without it the command can hang for seconds on an unreachable resolver.
-P
Show port numbers rather than service names, so you see 8080 instead of http-alt.
-iTCP:8080
Filter to internet sockets, protocol TCP, port 8080. Swap in any port, or a range like 8000-8100.
-sTCP:LISTEN
Keep only sockets in the LISTEN state, which drops the browser tabs and clients also talking to that port.

Sample output

COMMAND   PID   USER   FD   TYPE   DEVICE   NODE NAME
node    48213    ada   23u  IPv6  0x9a3f1   TCP *:8080 (LISTEN)

PID 48213 is the one to stop. kill 48213 asks it politely; add -9 only if it ignores you.

When you would reach for it

Any “address already in use” error, a dev server that survived a closed terminal, or a container that mapped a port you wanted. It is also a quick audit tool: drop the port filter and you get every listener on the machine.

Gotchas

  • Without sudo you only see your own processes, so a system service can look invisible.
  • An empty result is a real answer. If nothing is listening, the port conflict is somewhere else, often a proxy or a container port mapping.
  • Docker holds ports via its own proxy, so the PID you find may belong to Docker rather than your app.

Variants

$ ss -ltnp | grep :8080

Linux, no lsof installed

$ kill -9 $(lsof -t -iTCP:8080 -sTCP:LISTEN)

Find and stop in one step. Check before you run it

lineage

lsof, short for list open files, was written by Vic Abell at Purdue University's PUCC (Purdue University Computing Center) in 1994. The idea was simple and radical: since Unix treats nearly everything as a file, a tool that maps open file descriptors back to their owning processes becomes a universal debugger for sockets, pipes, and actual files alike. Abell maintained lsof for over two decades, releasing version 4.0 in 2000, and the tool shipped as a default on Solaris, AIX, HP-UX, and eventually macOS. Linux distributions adopted it through the 1990s, though it was never part of the kernel source tree. The project moved to GitHub in 2021 under community stewardship after Abell's retirement.