Last Updated: February 25, 2016
·
1.391K
· garrick

Strace: Interrogate misbehaving Linux apps

Wondering why you're getting a core dump? Application freezing every time you do X? Exiting with no messages at all? What's going on?!?

With a bit of patience, you can often see for yourself with Strace: http://linux.die.net/man/1/strace

Strace (System Trace) allows you to start an application with, or even attach to an existing running application and find out what system calls are going between user and kernel mode.

To start eavesdropping on these system call conversations, use:

strace someapplication

To listen in on some currently running process, use:

strace -pSOME_PROCESS_PID

To listen only to specific system calls on a running process, use a valid expression (see man page):

strace -pSOME_PROCESS_PID -e trace=network

The above example would only output data from network related system calls.

With the right output expressions for filtering, strace can be invaluable when some badly behaved Linux application is simply refusing to tell you what's wrong. Anything from missing shared libraries to poorly formatted configuration files or the fact that some mysterious IP address doesn't respond to connections can be discovered when an application "refuses to talk about it".

This can also be a lifesaver on all flavors of test, UAT and production servers. Next time a Linux app is acting up without telling you why, don't guess: strace!