October 13, 2012

ltrace, strace, truss, pstack

ltrace is used to trace a process's library call.
strace is used to trace system call.

From below we can clearly see the difference:

[root@server335 root]# cat 1.c
#include 

int main(void)
{
    printf("hello, world!\n");
    puts("hello, world!\n");
    printf("hello, world! %d\n", 3);
    return 0;
}
[root@server335 root]# gcc -o a.out 1.c
[root@server335 root]# ./a.out
hello, world!
hello, world!

hello, world! 3
[root@server335 root]# ltrace ./a.out
__libc_start_main(0x4004d8, 1, 0x7fffe2c2e488, 0x400520, 0x400510 
puts("hello, world!"hello, world!
)                                                                            = 14
puts("hello, world!\n"hello, world!

)                                                                          = 15
printf("hello, world! %d\n", 3hello, world! 3
)                                                                  = 16
+++ exited (status 0) +++
[root@server335 root]# strace ./a.out
....
....
write(1, "hello, world!\n", 14hello, world!
)         = 14
write(1, "hello, world!\n", 14hello, world!
)         = 14
write(1, "\n", 1
)                       = 1
write(1, "hello, world! 3\n", 16hello, world! 3
)       = 16
exit_group(0)                           

From above we clearly see the difference between ltrace and strace.

truss is samiliar to strace, but it is for UNIX, not linux.

And pstack can show you a process's call stack which you should consider using oradebug inteadly in any condition.

Regarding how to use above tools to solve problem, you can refer to a example of my previous post: http://dbakevin.blogspot.mx/2012/03/solved-wierd-ping-issue-root-can-ping.html

0 Comments:

Post a Comment