linux · medium
Who Owns This Port / FD? — lsof & /proc/PID/fd
lsof maps descriptors to resources: find a port's owner (lsof -i / fuser), detect a leak by counting /proc/PID/fd against ulimit -n (ends in EMFILE), and solve 'df full but du empty' — a deleted-but-still-open file held by a process (lsof +L1).
🔑 Key line
lsof -i :PORT / fuser = who owns a port. /proc/PID/fd count vs ulimit -n = leak detection (ends in EMFILE). lsof +L1 = deleted-but-open files (df full, du empty).
The code
sudo lsof -i :8080 # which process owns a portsudo fuser 8080/tcp # just the PID (-k to kill)
ls /proc/1234/fd | wc -l # fd count vs ulimit -n (leak check)
# df full but du empty? a deleted file is still open:sudo lsof +L1 # files with link count 0What this lesson walks through
- 01Which process owns a port?
- 02Detect a descriptor leak
- 03'Disk full' but du finds nothing
lsof -i :PORT or fuser PORT/tcp names the process and PID holding a port — fuser -k even kills it.
See it animated — step by step, at your own pace
Unlock the full interactive walkthrough of Who Owns This Port / FD? — lsof & /proc/PID/fd and 100+ animated C++ interview lessons.