有用的工具strace

strace可以显示用户空间程序发出的全部系统调用。

strace echo ‘”hello”

将显示这个命令所有的系统调用。如果只关注其中的某种调用,可以用-e参数,如只关心open函数,

strace -e trace=open echo “hello”

或者trace open和close:

strace -e trace=open,close echo “hello”

输出如下:

open(“./tls/x86_64/libc.so.6”, O_RDONLY) = -1 ENOENT (No such file or directory)
open(“./tls/libc.so.6”, O_RDONLY)       = -1 ENOENT (No such file or directory)
open(“./x86_64/libc.so.6”, O_RDONLY)    = -1 ENOENT (No such file or directory)
open(“./libc.so.6”, O_RDONLY)           = -1 ENOENT (No such file or directory)
open(“/usr/lib/tls/x86_64/libc.so.6”, O_RDONLY) = -1 ENOENT (No such file or directory)
open(“/usr/lib/tls/libc.so.6”, O_RDONLY) = -1 ENOENT (No such file or directory)
open(“/usr/lib/x86_64/libc.so.6”, O_RDONLY) = -1 ENOENT (No such file or directory)
open(“/usr/lib/libc.so.6”, O_RDONLY)    = -1 ENOENT (No such file or directory)
open(“/etc/ld.so.cache”, O_RDONLY)      = 3
close(3)                                = 0
open(“/lib64/tls/libc.so.6”, O_RDONLY)  = 3
close(3)                                = 0
hello
Process 26347 detached



本文地址: http://www.bagualu.net/wordpress/archives/1178 转载请注明




发表评论

电子邮件地址不会被公开。 必填项已用*标注