🐧 Linux / Shell Scripting
Advanced
How do you use strace and ltrace for debugging in Linux?
Answer
strace traces system calls made by a process. strace command runs and traces the command. strace -p PID attaches to a running process. strace -e trace=open,read,write filters specific syscalls. strace -f follows child processes. strace -o output.txt saves to file. strace -T shows time spent in each syscall. Useful for: debugging "permission denied" (which files?), "file not found" (which path?), slow processes (which syscall blocks?). ltrace traces library calls (libc functions like malloc, fopen). ltrace -p PID command. Together, strace and ltrace are powerful for black-box debugging without source code.