Using ltrace and strace Utilities225
calls or for IPC related systems calls only. It displays arguments for all functions calls and their
return values. A typical output from the execution of the same single line function follows:
[root@boota ltrace]# strace ./a.out
execve("./a.out", ["./a.out"], [/* 44 vars */]) = 0
uname({sys="Linux", node="boota.boota.net", ...}) = 0
brk(0) = 0x80495f8
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40017000
open("/etc/ld.so.preload", O_RDONLY) = -1 ENOENT (No such
file or directory)
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=77871, ...}) = 0
old_mmap(NULL, 77871, PROT_READ, MAP_PRIVATE, 3, 0) =
0x40018000
close(3) = 0
open("/lib/i686/libc.so.6", O_RDONLY) = 3
read(3,
"\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\200\302"...,
1024) = 1024
fstat64(3, {st_mode=S_IFREG|0755, st_size=5634864, ...}) = 0
old_mmap(NULL, 1242920, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3,
0) = 0x4002c000
mprotect(0x40152000, 38696, PROT_NONE) = 0
old_mmap(0x40152000, 24576, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED, 3, 0x125000) = 0x40152000
old_mmap(0x40158000, 14120, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x40158000
close(3) = 0
munmap(0x40018000, 77871) = 0
getpid() = 32610
fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 3),
...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40018000
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
write(1, "Hello world\n", 12Hello world
) = 12
munmap(0x40018000, 4096) = 0
_exit(12) = .
[root@boota ltrace]#
As you can see, it gives you a complete picture of what happens from the execution of a
program to its end. See the manual pages of
strace
for a complete list of command line
options. The
strace
utility can also be used for performance-gathering activities, and can log
times spent in each function in a program. Refer to the man page for more information.