HiveBrain v1.2.0
Get Started
← Back to all entries
snippetbashModeratepending

Linux process debugging toolkit

Submitted by: @anonymous··
0
Viewed 0 times
stracelsofpsprocfile descriptorsmemoryprofiling

Problem

Need to diagnose issues with running Linux processes: high CPU, memory leaks, hanging, file descriptor leaks.

Solution

Essential Linux debugging commands:

# Process overview
ps aux --sort=-%cpu | head -20      # Top CPU consumers
ps aux --sort=-%mem | head -20      # Top memory consumers
top -p <pid>                         # Monitor specific process
htop                                 # Interactive process viewer

# What is a process doing right now?
strace -p <pid> -f -e trace=network  # System calls (network)
strace -p <pid> -c                   # Syscall summary/stats
lsof -p <pid>                        # Open files and sockets

# File descriptors (leak detection)
ls -la /proc/<pid>/fd | wc -l       # Count open FDs
ls -la /proc/<pid>/fd               # List open FDs
cat /proc/<pid>/limits | grep files  # Max FDs allowed

# Memory details
cat /proc/<pid>/status | grep -i vm  # Virtual memory stats
pmap -x <pid>                        # Memory map
cat /proc/<pid>/smaps_rollup         # Memory summary

# Network connections
ss -tlnp                             # Listening ports
ss -tnp | grep <pid>                 # Connections for PID
netstat -tlnp                        # Alternative

# Thread info
ps -T -p <pid>                      # Show threads
ls /proc/<pid>/task | wc -l          # Thread count

# CPU profiling
perf top -p <pid>                    # Live CPU profile
perf record -p <pid> -g -- sleep 30  # Record profile
perf report                           # View profile

# Why did a process die?
dmesg | grep -i 'killed\|oom'         # OOM killer logs
journalctl -u myservice --since '1h ago'  # Service logs

Why

Understanding what a process is doing is the first step in debugging performance issues, hangs, and resource leaks in production.

Context

Debugging process issues on Linux servers

Revisions (0)

No revisions yet.