SHARE
Facebook X Pinterest WhatsApp

Using Strace to Trace Problems

Written By
thumbnail Joe Brockmeier
Joe Brockmeier
Oct 25, 2010
ServerWatch content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More



More on open source software

Having trouble figuring out why Apache isn’t starting, or another program is crashing and burning, and the logfiles are giving no clue? Time to reach for strace.

If you’re having trouble figuring out why a program keeps crashing and burning, consider Strace, an easy-to-use diagnostic tool. More experienced users will find Strace handy for performance testing and more.

What’s strace? The strace utility is used to run a command and display its system calls, so you can see exactly what the program is doing until it exits. Experienced users can work with strace to do performance testing and so on, but even beginners can use strace as a diagnostic tool to see why a program is crashing.

Here’s what you do. First, simply start your application or service using Strace, like so:

strace commandname

You’ll then see a bunch of output to the terminal. For example, running man without an argument would looks like this:

execve("/usr/bin/man", ["man"], [/* 37 vars */]) = 0
brk(0)                                  = 0x8d94000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb774d000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3

... 
open("/usr/share/locale-langpack/en/LC_MESSAGES/man-db.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
write(2, "What manual page do you want?n", 30What manual page do you want?
) = 30
ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(0, SNDCTL_TMR_START or TCSETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
exit_group(1)                           = ?

I trimmed out a bunch of material, but you can see the first few lines and the final lines that indicate man has encountered an error. Specifically, no file or directory is specified. Now it’s not a major puzzle why man exited with an error here because it prints out the helpful “What manual page do you want?” But if it didn’t, you’d have a clue with the error -1 ENOENT (No such file or directory).

Looking for errors? Usually, they’ll have an -1 to indicate an error. Not all errors are fatal, but they can provide useful clues.

You can use the -u username option to run as a specific user. This allows you to be logged in as root and run applications as the appropriate user for the service. Note that you usually will be running strace as root, so this option comes in handy.

What if a process is already running? If you must examine some application flakiness while a process is still running, you can use the -p PID option to examine a running process, where PID is the process ID number.

As always, it’s a good idea to familiarize yourself with a tool before you need it. Spend some time playing with strace now, and the next time you have a buggy app to contend with, you’ll know your way around it when it counts.

Joe ‘Zonker’ Brockmeier is a freelance writer and editor with more than 10 years covering IT. Formerly the openSUSE Community Manager for Novell, Brockmeier has written for Linux Magazine, Sys Admin, Linux Pro Magazine, IBM developerWorks, Linux.com, CIO.com, Linux Weekly News, ZDNet, and many other publications. You can reach Zonker at jzb@zonker.net and follow him on Twitter.

Follow ServerWatch on Twitter

thumbnail Joe Brockmeier

Joe Brockmeier is the editorial director of the Red Hat Blog. He joined Red Hat in 2013 as part of the Open Source and Standards (OSAS) group, now the Open Source Program Office (OSPO). Prior to Red Hat, Brockmeier worked for Citrix on the Apache OpenStack project, and was the first OpenSUSE community manager for Novell between 2008-2010. Brockmeier also has an extensive history in the tech press and publishing, having been editor-in-chief of Linux Magazine, editorial director of Linux.com, and a contributor to LWN.net, ZDNet, UnixReview.com, and many others.

Recommended for you...

What Is a Container? Understanding Containerization
What Is a Print Server? | How It Works and What It Does
Nisar Ahmad
Dec 8, 2023
6 Best Linux Virtualization Software for 2024
What Is a Network Policy Server (NPS)? | Essential Guide
ServerWatch Logo

ServerWatch is a top resource on servers. Explore the latest news, reviews and guides for server administrators now.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.