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.

[/problem]

[solution]

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

[/solution]

[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

[/example]

[reference]

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

[/reference]

If you have found my website useful, please consider buying me a coffee below 😉

Leave a Reply

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