On Linux, everything is a file β regular files, directories, sockets, pipes, and devices. When something goes wrong, lsof tells you which processes hold which files. When network issues strike, ss gives you socket state with far less overhead than netstat.
lsof /var/log/syslogOutput shows every process with an open handle on that file, including its PID and file descriptor.
lsof -p 1234Invaluable when a process is behaving oddly β check if it has leaked file descriptors, holds stale locks, or unexpectedly opened too many connections.
lsof -i :8080lsof -iCombine with -P to avoid DNS lookups and -n to avoid hostname resolution:
lsof -i -P -nWhen you delete a file but a process keeps it open, the disk space is not released:
lsof -nP | grep "(deleted)"Fix by restarting the process or clearing the file descriptor:
: > /proc/$PID/fd/$FD# Listen on all TCP/UDP ports, no name resolution
lsof -iTCP -sTCP:LISTEN -P -n
# Unix domain sockets
lsof -U
# Show file descriptor size and offset
lsof -o -p $PIDss is the modern replacement for netstat. It reads socket information directly from the kernel and is significantly faster, especially on systems with thousands of connections.
ss -ass -tss -tlnpBreakdown: -t TCP, -l listening, -n numeric, -p show process.
# All established connections
ss -t state established
# Connections in TIME_WAIT (potential port exhaustion)
ss -t state time-wait
# Or with numeric values
ss -t state fin-wait-1
ss -t state close-waitss -tlnp sport = :80
ss -tlnp dport = :443ss -tlpThe -p flag shows the PID and process name β essential for identifying which service owns each socket.
umount /mnt/data
# device is busy
lsof /mnt/dataFind the offending process and either kill it or change its working directory.
ss -tlnp sport = :3000Shows the PID holding port 3000 so you can restart or kill it.
ss -sShows total socket counts by state. If time-wait is high, you may need to tune net.ipv4.tcp_tw_reuse.
ss -t -o state established -pWatch established connections grow in real time. Combine with watch:
watch -n 1 'ss -t state established | wc -l'On a server with 100k connections:
netstat -a β 3-5 seconds, high CPUss -a β under 0.1 seconds, minimal CPUAlways use ss over netstat. On modern distros netstat is often not even installed by default.
Related Articles
lsof and ss β Open Files and Sockets Deep Dive
Master lsof and ss to find what files are open, which processes hold sockets, and why you cannot unmount a filesystem.
DNS Demystified 4: Troubleshooting DNS Issues
A systematic approach to diagnosing DNS problems β from NXDOMAIN to SERVFAIL, slow resolution, and misconfigured zones.
tcpdump β Network Packet Analysis for Sysadmins
Use tcpdump to capture and analyze network traffic like a senior network engineer. Debug DNS, TCP handshakes, and slow connections.