strace
debuggingLinux
The strace command is one of the most frequently used commands in Linux/Unix-like operating systems. strace Trace system calls and signals
Quick Reference
Command Name:
strace
Category:
debugging
Platform:
Linux
Basic Usage:
strace [options] [arguments]
Common Use Cases
Syntax
strace [options] [command [args]]
Options
Option | Description |
---|---|
-c |
Count time, calls, and errors for each system call and report a summary |
-d |
Show debug output of strace itself |
-f |
Trace child processes as they are created by currently traced processes |
-ff |
With -o, write each process trace to filename.pid |
-h |
Print help summary |
-i |
Print instruction pointer at time of system call |
-k |
Print stack trace for each system call (experimental) |
-o filename |
Write the trace output to filename instead of stderr |
-p pid |
Attach to the process with the process ID pid and begin tracing |
-s strsize |
Specify the maximum string size to print (default 32) |
-t |
Prefix each line of the trace with the time of day |
-tt |
Prefix each line of the trace with the time of day including microseconds |
-ttt |
Prefix each line with seconds since epoch |
-T |
Show the time spent in system calls |
-v |
Print unabbreviated versions of environment, stat, termios, etc. |
-V |
Print the version of strace |
-x |
Print all non-ASCII strings in hexadecimal |
-xx |
Print all strings in hexadecimal |
-y |
Print paths associated with file descriptor arguments |
-e expr |
A qualifying expression which modifies which events to trace |
Expression (-e) Option | Description |
---|---|
-e trace=set |
Trace only the specified set of system calls |
-e trace=file |
Trace all system calls which take a file name as an argument |
-e trace=process |
Trace all system calls related to process management |
-e trace=network |
Trace all network-related system calls |
-e trace=signal |
Trace all signal-related system calls |
-e trace=ipc |
Trace all IPC-related system calls |
-e trace=desc |
Trace all file descriptor-related system calls |
-e trace=memory |
Trace all memory mapping related system calls |
-e signal=set |
Trace only the specified signals |
-e read=set |
Show only read operations on specified file descriptors |
-e write=set |
Show only write operations on specified file descriptors |
Examples
How to Use These Examples
The examples below show common ways to use the strace
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
# Basic Examples Basic
strace ls -l