Debugging Programs on Linux with strace and ltrace

When a program misbehaves and you have no source code or logging to go on, strace and ltrace show you exactly what it’s actually doing at the system and library call level.

# Trace all system calls a program makes
strace ./myprogram

# Trace an already-running process by PID
sudo strace -p 12345

# Filter to a specific category - file operations, for example
strace -e trace=open,openat,read,write ./myprogram

# Time each syscall - useful for finding where a program hangs
strace -T ./myprogram

# Summarize syscall counts and time spent - a quick profiling view
strace -c ./myprogram
# ltrace shows LIBRARY calls instead of system calls
ltrace ./myprogram

A Real Diagnostic Example

A program that “hangs” with no error is often just blocked waiting on a syscall — strace reveals exactly which one (often a network connect or a file open on a missing/locked resource), turning a mysterious hang into an immediately obvious cause without needing access to the program’s source code at all.