Linux Debugging strace

Problem

You have a problem with a process, running some job on a Linux box and need to see some debug information.

Sometimes the problem is a missing library, etc and you need to spot the missing dependency.

Symptoms could be a binary runs fine on one system and fails on another.



Solution

On Linux use strace, which takes basically the same options as truss on Solaris.



Example


You just use -e, like this:


strace -e’open’ ls
open(”/etc/ld.so.preload”, O_RDONLY) =
-1 ENOENT (No such file or directory)
open(”/etc/ld.so.cache”, O_RDONLY) = 3
open(”/lib/tls/librt.so.1″, O_RDONLY) = 3
open(”/lib/libtermcap.so.2″, O_RDONLY) = 3
open(”/lib/libacl.so.1″, O_RDONLY) = 3
open(”/lib/tls/libc.so.6″, O_RDONLY) = 3
open(”/lib/tls/libpthread.so.0″, O_RDONLY) = 3
open(”/lib/libattr.so.1″, O_RDONLY) = 3
open(”/usr/lib/locale/locale-archive”, O_RDONLY|O_LARGEFILE) = 3
open(”.”, O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY) = 3
open(”/etc/mtab”, O_RDONLY) = 3
open(”/proc/meminfo”, O_RDONLY) = 3



Reference

[tags]Linux strace, Linux, strace, UNIX Coding School[/tags]



Leave a Reply

Your email address will not be published. Required fields are marked *