Session and utilities
The strace command
Shows the system calls a program makes, to debug it.
Most useful options
-fFollows the child processes the program creates too-e trace=grupoShows only one group of calls, such as file for files or network for networking-p PIDAttaches to a process that is already running, without restarting it-o archivoWrites the trace to a file instead of the screen-cAt the end, shows a table with the number of calls, their time and their errors-tPrefixes each call with the timeCopy-ready examples
$ strace -c lssummarizes how many calls ls makes and how long each one takes.$ strace -e trace=openat cat /etc/hostnameshows only the calls that open files while cat reads the machine name.$ strace -f -o traza.txt ./mi-programafollows child processes and saves the trace to a file to review later.$ strace -tt -p 4242 -e trace=readattaches to a running process (example PID) and shows its reads with exact times. Only your own processes.You can try them in the browser terminal: it does not touch your computer.
Typical mistakes
- The output is huge: filter with -e trace= or save it to a file with -o.
- By default strings are cut at 32 bytes; with -s N you raise the limit to see longer strings.
- Tracing slows the program down, especially with -f, so the timings do not reflect its real pace.
- Linux can block attaching to other processes through Yama (ptrace_scope). If it fails, check the permissions instead of forcing it.
Differences from similar commands
ltrace: traces calls to functions in shared libraries, not system calls.- lsof: lists the files and sockets a process has open, without following its activity over time.
gdb: debugs at the code level: sets breakpoints and inspects memory. strace only observes the boundary with the system.
Security
The trace includes the data the program reads and writes, and with it passwords or tokens if it handles them. Review it before sharing it, and do not attach strace to other users' processes.
FAQ
When is strace worth using?
When a program fails without a clear message or cannot find a file: the trace shows the open and stat calls it makes and the path where it gets stuck.
Can I trace a program that is not mine?
You can trace your own processes. Tracing other users' processes requires permission, and the trace can expose their data.
Why does the output cut off in the middle of a string?
Because strace prints only the first 32 bytes of each string by default. Use -s with a larger number to see more.
Learn to actually use it
The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.
Start the free course