Coder Perfect

How should strace be used?


When all else fails to debug on Linux, a colleague once encouraged me to use strace as a last resort.

I attempted to understand the science behind this weird tool, but I am not a system administrator, so my efforts were in vain.


How does this stuff function in a nutshell, in basic terms?

Asked by e-satis

Solution #1

Overview of the Strace strace can be thought of as a light debugger. It allows a programmer or user to quickly determine how a software interacts with the operating system. It accomplishes this by keeping track of system calls and signals.

Uses When you don’t have source code or don’t want to bother with it, this is a good option. Also handy for your own code if you don’t want to open GDB but want to see how external interactions work.

An excellent start. Just the other day, I came across this introduction to strace usage: hi there, world

Answered by John Mulder

Solution #2

To put it another way, strace traces all system calls made by a program, as well as their return codes. Consider file/socket operations, as well as a variety of others.

It’s best if you know how to use C because system calls are more correctly referred to as standard C library calls here.

Consider the program /usr/local/bin/cough. Simply type in:

strace /usr/local/bin/cough <any required argument for cough here>


strace -o <out_file> /usr/local/bin/cough <any required argument for cough here>

to save to the ‘out file’

stderr will get all strace output (beware, the sheer volume of it often asks for a redirection to a file). In the most basic circumstances, your application will terminate with an error, and you’ll be able to view the last interactions it had with the OS in the strace output.

There should be more information available with:

man strace

Answered by bltxd

Solution #3

strace displays a list of all system calls made by the process to which it is applied. If you don’t know what system calls mean, you won’t be able to get much mileage from it.

If your problem involves files, paths, or environment values, however, running strace on the problematic program and redirecting the output to a file, then grepping that file for your path/file/env string, may help you see what your program is actually attempting to do, as opposed to what you expected.

Answered by Asaf Bartov

Solution #4

Strace stands out as a useful tool for debugging production systems when you can’t afford to run them in a debugger. We’ve utilized strace in the following two scenarios in particular:

See my answer to this topic for an example of analyzing with strace.

Answered by terson

Solution #5

I frequently use strace to troubleshoot permission issues. The method is as follows:

$ strace -e trace=open,stat,read,write gnome-calculator

The command that you want to run is gnome-calculator.

Answered by Jeff Sheffield

Post is based on