How do you find which process is using a port on Linux?
Assesses fundamental understanding of Linux Administration conventions, runtime behavior, and memory/performance considerations.
Hiring managers look for precision, avoidance of ambiguous jargon, and ability to explain trade-offs under real production conditions.
Use ss, lsof, or fuser depending on what is installed.
sudo ss -ltnp | grep ':8080'
sudo lsof -i :8080
sudo fuser -n tcp 8080
- ss -ltnp lists listening TCP sockets with the owning process (-p) and numeric ports (-n). It is the modern replacement for netstat.
- lsof -i :8080 shows open files and sockets for that port.
- fuser -n tcp 8080 prints the PID using the port.
You usually need root or sudo to see processes owned by other users. To identify what a PID is, run ps -fp <pid> or read /proc/<pid>/cmdline. To free the port, stop the process with kill <pid> or, if it ignores SIGTERM, kill -9 <pid>. On systemd hosts, systemctl status can map the process to its unit.
Candidate Response Strategy & Interview Tips
- Start with a concise one-sentence summary: Deliver a direct, confident answer first before expanding into nuances.
- Demonstrate real-world trade-offs: Discuss where this approach excels and when you would avoid it in production systems.
- Discuss complexity & edge cases: Proactively explain time/space complexity or boundary conditions (null values, scale limits).
- Prepare for interviewer follow-ups: Technical hiring panels frequently probe deeper into concurrency, backward compatibility, or alternative libraries.