Drill: Trace Syscalls with strace¶
Goal¶
Use strace to observe system calls made by a process to diagnose failures, permission issues, and missing files.
Setup¶
- Linux system with strace installed (
apt install straceoryum install strace) - Root or CAP_SYS_PTRACE capability to trace other users' processes
Commands¶
Trace a command from start to finish:
Attach to a running process:
Filter by syscall category (file, network, process):
strace -e trace=file ls /tmp
strace -e trace=network curl -s https://example.com
strace -e trace=process bash -c 'echo hello'
Show timestamps and call duration:
Summarize syscall statistics:
Write trace output to a file:
Follow forked children:
What to Look For¶
ENOENT(No such file or directory) reveals missing config files or librariesEACCES(Permission denied) pinpoints permission failuresECONNREFUSEDshows network connection failures- The
-csummary reveals which syscalls dominate execution time
Common Mistakes¶
- Forgetting
-fto follow child processes (misses forked workers) - Tracing without filtering, producing overwhelming output
- Not redirecting strace output (it goes to stderr by default)
- Tracing production processes without understanding the performance overhead
Cleanup¶
Detach from traced processes with Ctrl+C. strace does not modify the traced process.