Skip to content

Instantly share code, notes, and snippets.

@zealfire
Created March 24, 2018 22:58
Show Gist options
  • Save zealfire/df082a0d9945c3507ec7bab93883121e to your computer and use it in GitHub Desktop.
Save zealfire/df082a0d9945c3507ec7bab93883121e to your computer and use it in GitHub Desktop.
Strace is a debugging tool that will help you troubleshoot issues.
Strace monitors the system calls and signals of a specific program. It is helpful when you do not have the source code and would like to debug the execution of a program. strace provides you the execution sequence of a binary from start to end.
This article explains 7 strace examples to get you started.
1. Trace the Execution of an Executable
You can use strace command to trace the execution of any executable. The following example shows the output of strace for the Linux ls command.
$ strace ls
2. Trace a Specific System Calls in an Executable Using Option -e
Be default, strace displays all system calls for the given executable. To display only a specific system call, use the strace -e option as shown below.
$ strace -e open ls
4. Execute Strace on a Running Linux Process Using Option -p
You could execute strace on a program that is already running using the process id. First, identify the PID of a program using ps command.
For example, if you want to do strace on the firefox program that is currently running, identify the PID of the firefox program.
$ ps -C firefox-bin
PID TTY TIME CMD
1725 ? 00:40:50 firefox-bin
Use strace -p option as shown below to display the strace for a given process id.
$ sudo strace -p 1725 -o firefox_trace.txt
$ tail -f firefox_trace.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment