← All writing

Linux Systems Performance Troubleshooting: strace, lsof, tcpdump & Signals

· Sourabh G Kulkarni

A practical guide to diagnosing production container and node failures using strace system call tracing, lsof file descriptor audits, and tcpdump packet analysis.

Linux Systems Performance Troubleshooting: strace, lsof, tcpdump & Signals

When application metrics in Grafana show an endpoint timing out or CPU pegged at 100%, and application logs show nothing useful, standard application-level debugging has reached its limit. You need to drop down into the Linux kernel layer.

Every interaction an application has with the outside world—opening a file, reading a socket, sending a packet, or allocating memory—must pass through the Linux Kernel via System Calls (Syscalls).

Here is the SRE and DevOps playbook for diagnosing stubborn production issues using strace, lsof, tcpdump, and Linux signals.

flowchart LR
    App["Container / Node Process"]
    
    subgraph Tools["Diagnostic Kernel Instrumentation Tools"]
        Strace["strace (Intercept System Calls)"]
        Lsof["lsof (Audit Open File Descriptors)"]
        Tcpdump["tcpdump (Sniff Network Packets)"]
    end

    subgraph Kernel["Linux Kernel Subsystems"]
        Sys["Syscall Interface (read, write, poll, connect)"]
        VFS["Virtual File System (sockets, pipes, disks)"]
        Net["Network Stack (TCP/IP, iptables, eBPF)"]
    end

    App -->|Requests| Sys
    Strace -.->|Attaches via ptrace| Sys
    Lsof -.->|Inspects /proc/PID/fd| VFS
    Tcpdump -.->|AF_PACKET socket| Net

1. strace: Finding Where a Process is Freezing

strace intercepts and records the system calls made by a process. It answers the question: "What is this thread waiting for right now?"

# Attach to a frozen or spinning process by PID
strace -p <PID> -f -T -tt

# Flags:
# -f : Follow child threads/processes
# -T : Print time spent inside each system call (vital for latency bottlenecks)
# -tt: Print microsecond timestamps

Spotting Common Bottlenecks in strace:

  • Hung on futex(..., FUTEX_WAIT, ...): The application is deadlocked on an internal thread lock.
  • Hung on connect(3, {sa_family=AF_INET, sin_port=htons(5432), ...}): The application is stuck attempting to establish a TCP connection to an unreachable database or firewall block.
  • Repeated stat(...) = -1 ENOENT: Missing shared library, configuration file, or search path misconfiguration.

2. lsof: The Mystery of "No Space Left on Device"

In Linux, everything is a file: disk files, network sockets, character devices, and inter-process pipes are all tracked as File Descriptors (FDs).

The Deleted File Disk Leak Trap

Have you ever seen df -h report 100% full, but du -sh * shows only 10 GB used? This occurs when a log file is deleted (rm access.log), but an active process (like Nginx or Java) still holds an open file descriptor to it. Linux will not reclaim disk blocks until all processes close the descriptor!

# Find deleted files still held open by processes
lsof | grep '(deleted)'

# Identify the PID and restart or reload the service to free disk space immediately:
systemctl reload nginx

3. tcpdump: Packet Inspection in Container Namespaces

When network packets mysteriously drop between two pods, tcpdump confirms whether the packet ever left the virtual network interface (veth):

# 1. Capture traffic on port 8080 excluding SSH noise
tcpdump -nnvv -i any port 8080 -c 100

# 2. Inspect DNS resolution issues (Port 53 UDP)
tcpdump -n -i any udp port 53

# 3. Write capture to file for Wireshark analysis
tcpdump -i eth0 -w dump.pcap

4. Understanding Linux Process Signals

SignalNumberCatchable?Purpose
SIGTERM15YesGraceful termination request. The app should stop accepting new connections, finish in-flight requests, and exit.
SIGKILL9NoImmediate kernel termination. The process cannot catch or clean up after this signal. Used when container exceeds memory (OOMKilled) or fails shutdown timeouts.
SIGHUP1YesTerminal disconnected, but in daemons (Nginx, Prometheus) standardly triggers a hot configuration reload without process restarts.

Knowing how to trace syscalls, audit open file descriptors, and inspect packets equips you to solve any production failure that standard application logs fail to reveal.