debugging · advanced
Debugging: Live Deployment — Crash, CPU, Memory, Hung Process, Deploy Checklist
Live production debugging workflow for C++ backends. Crash: check journalctl → /var/crash/ for core dump → gdb ./app core → bt → frame → fix. High CPU: top -H -p PID (per-thread) → perf top -p PID (live hotspot) → perf record → flamegraph. Memory growth: watch /proc/PID/status VmRSS; /proc/PID/smaps Private_Dirty; fd count for fd leaks. Hung process: strace -p PID → look for futex_wait repeated = deadlock; gdb -p PID → thread apply all bt → identify which threads hold which locks. Network: ss -tnp | grep app; check connection count, TIME_WAIT accumulation. Runtime signals: SIGUSR1/SIGHUP for log-level/config reload without restart. Deploy: cmake Release → objcopy debug symbols out → strip binary → rolling deploy → health check → atomic symlink rollback if health check fails.
Production debug: journalctl → gdb ./app core → bt; high CPU: top -H -p PID → perf top -p PID; memory leak: watch VmRSS; hung: strace -p → futex_wait → gdb -p → thread apply all bt; deploy: strip binary, keep .debug, health-check, atomic rollback.
The code
# Live production debug checklist (C++ backend)
# 1. First: is it a crash? Check for core dumps / crash logsls /var/crash/ && journalctl -u myapp -n 100 --no-pagergdb ./myapp /var/crash/core.1234 # post-mortem
# 2. High CPU? Find the processtop -H -p $(pgrep myapp) # -H: show threadsperf top -p PID # live hotspot view
# 3. Memory growth? Check RSS trendcat /proc/PID/status | grep VmRSScat /proc/PID/smaps | grep Private_Dirty
# 4. Hung process? Stuck in what syscall?strace -p PID -e trace=all -f 2>&1 | tail -20# -f: follow threads -e: filter syscallsls -la /proc/PID/fd | head -30 # check file descriptor leakcat /proc/PID/limits # resource limits
# 5. Network issues?ss -tnp | grep myapp # all TCP connectionsnetstat -snp | grep myapp
# 6. Deadlock / high lock contentionsudo perf record -g -p PID -- sleep 10# look for futex_wait in perf report → deadlock or lock contentiongdb -p PID → thread apply all bt # attach to live process
# 7. Logging without restart (runtime log level)kill -SIGUSR1 PID # if SIGUSR1 raises log level in your appkill -SIGHUP PID # if SIGHUP triggers config reload
# 8. Build and deploy checklist# - Build: cmake --build . --config Release -- -j$(nproc)# - Strip: objcopy --only-keep-debug app app.debug && strip app# - Deploy: rsync + restart with rolling update# - Verify: curl -s http://localhost/health | jq .# - Rollback: symlink swap (atomic) if health check failsWhat this lesson walks through
- 01Live debug checklist — first 60 seconds
- 02Crash diagnosis — core dump + GDB post-mortem
- 03High CPU — find the hot thread
- 04Memory growth — /proc/PID/status + smaps
- 05Hung process — strace + GDB live attach
- 06Deploy checklist — build, strip, verify, rollback
A live production issue follows a standard triage order. First: is the process running or dead? Check core dumps and logs. Second: CPU or memory? Use top -H and /proc/PID/status. Third: stuck in a syscall? Use strace -p. Fourth: network/fd leak? Check /proc/PID/fd. This structured approach avoids random guessing under pressure.
See it animated — step by step, at your own pace
Unlock the full interactive walkthrough of Debugging: Live Deployment — Crash, CPU, Memory, Hung Process, Deploy Checklist and 100+ animated C++ interview lessons.