linux · medium
Inspect Sockets — ss, netstat, Connection States & Queues
Reading sockets with ss: is the service listening and on a reachable address; on live connections, Recv-Q (app behind) vs Send-Q (peer behind); a state census separating TIME_WAIT churn from a CLOSE_WAIT fd leak; and the listening-socket backlog overflow.
🔑 Key line
ss -ltnp: am I listening (0.0.0.0 vs 127.0.0.1)? ss -tnp: Recv-Q=app behind, Send-Q=peer behind. State census: TIME_WAIT (churn) vs CLOSE_WAIT (your fd leak). Listening Recv-Q=accept-queue depth.
The code
ss -ltnp # listening tcp sockets + owning processss -tnp # established connections + queues# Recv-Q = bytes waiting for the APP to read()# Send-Q = bytes sent, not yet ACKed by the peer
# Census of connection statesss -tan | awk '{print $1}' | sort | uniq -c | sort -rn
# Listening socket: Recv-Q = accept-queue depth, Send-Q = backlog maxnetstat -s | grep -i 'overflow\|listen'What this lesson walks through
- 01Is it listening, and where?
- 02Recv-Q vs Send-Q — who's behind?
- 03Read the state census
- 04Is the listen backlog overflowing?
0.0.0.0 = reachable from the network; 127.0.0.1 = localhost-only — the classic 'works in test, dead in prod' bug.
See it animated — step by step, at your own pace
Unlock the full interactive walkthrough of Inspect Sockets — ss, netstat, Connection States & Queues and 100+ animated C++ interview lessons.