strace(1)
Trace system calls and signals made by a process to diagnose problems and understand program behavior.
Synopsis
strace [OPTION]... COMMAND [ARG]...Description
strace is a diagnostic tool that intercepts and logs all system calls and signals received by a process. It shows you exactly which kernel functions a program calls, their arguments, and return values. This is invaluable for debugging why a program fails, hangs, or behaves unexpectedly.
By default, strace writes output to stderr. You can redirect it to a file or filter by specific system calls. It works on compiled binaries without needing source code or recompilation.
Common options
| Flag | What it does |
|---|---|
-e EXPR | filter which syscalls/signals to trace; e.g. -e open,read or -e !mmap |
-o FILE | write output to FILE instead of stderr |
-p PID | attach to and trace an existing process by PID |
-f | follow child processes created by fork/clone |
-c | count syscalls and print summary statistics; don't print individual calls |
-s SIZE | print up to SIZE characters for string arguments (default 32) |
-v | print all arguments fully; don't abbreviate long structures or arrays |
-x | print all non-ASCII bytes in hex |
-t | prefix output with wall-clock time |
-T | show time spent in each syscall |
Examples
trace all syscalls made by ls; watch it open files, stat paths, read directories
strace ls /tmptrace only file operations; filter to see just open, read, and write syscalls
strace -e openat,read,write cat file.txtattach to running process 1234 and save trace to trace.log without disrupting terminal
strace -p 1234 -o trace.logfollow forks and trace all execve calls; see child processes and their exec chains
strace -f -e execve bash -c 'echo hello'summarize syscall counts and time; useful for quick performance profiling
strace -c curl https://example.comtrace only file-related syscalls and view first 20 lines
strace -e trace=file ls -la 2>&1 | head -20trace signals; see when and how the process receives SIGTERM
strace -e signal=SIGTERM sleep 10 &