29.2. strace - trace system calls and signals

简介:
-tt  在每行输出的前面,显示毫秒级别的时间
-T   显示每次系统调用所花费的时间
-v   对于某些相关调用,把完整的环境变量,文件stat结构等打出来.
-f   跟踪目标进程,以及目标进程创建的所有子进程.
-e  控制要跟踪的事件和跟踪行为,比如指定要跟踪的系统调用名称.
     trace=file     跟踪和文件访问相关的调用(参数中有文件名)
     trace=process  和进程管理相关的调用,比如fork/exec/exit_group
      trace=network  和网络通信相关的调用,比如socket/sendto/connect
      trace=signal    信号发送和处理相关,比如kill/sigaction
      trace=desc  和文件描述符相关,比如write/read/select/epoll等    
      trace=ipc 进程见通信相关,比如shmget等
      
-o  把strace的输出单独写到指定的文件
-s  当系统调用的某个参数是字符串时,最多输出指定长度的内容,默认是32个字节.
-p  指定要跟踪的进程pid,要同时跟踪多个pid,重复多次-p选项即可.		
		
strace -tt -T -v -f -e trace=file -o ~/strace.log.2 -s 1024 -p  25849		
		

strace -v ps -e 2

strace -v ls

neo@netkiller:~/workspace/Document$ strace -c ls
Docbook  makedoc  Tex
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
  -nan    0.000000           0        11           read
  -nan    0.000000           0         1           write
  -nan    0.000000           0        38        13 open
  -nan    0.000000           0        27           close
  -nan    0.000000           0        25           fstat
  -nan    0.000000           0        39           mmap
  -nan    0.000000           0        16           mprotect
  -nan    0.000000           0         4           munmap
  -nan    0.000000           0         3           brk
  -nan    0.000000           0         2           rt_sigaction
  -nan    0.000000           0         1           rt_sigprocmask
  -nan    0.000000           0         2           ioctl
  -nan    0.000000           0         9         9 access
  -nan    0.000000           0         1           execve
  -nan    0.000000           0         1           fcntl
  -nan    0.000000           0         2           getdents
  -nan    0.000000           0         1           getrlimit
  -nan    0.000000           0         1           statfs
  -nan    0.000000           0         1           arch_prctl
  -nan    0.000000           0         3         1 futex
  -nan    0.000000           0         1           set_tid_address
  -nan    0.000000           0         1           set_robust_list
------ ----------- ----------- --------- --------- ----------------
100.00    0.000000                   190        23 total
			
neo@netkiller:~/workspace/Document$ strace -f -e open ls >/dev/null
open("/etc/ld.so.cache", O_RDONLY)      = 3
open("/lib/librt.so.1", O_RDONLY)       = 3
open("/lib/libselinux.so.1", O_RDONLY)  = 3
open("/lib/libacl.so.1", O_RDONLY)      = 3
open("/lib/libc.so.6", O_RDONLY)        = 3
open("/lib/libpthread.so.0", O_RDONLY)  = 3
open("/lib/libdl.so.2", O_RDONLY)       = 3
open("/lib/libattr.so.1", O_RDONLY)     = 3
open("/proc/filesystems", O_RDONLY)     = 3
open("/usr/lib/locale/locale-archive", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/locale.alias", O_RDONLY) = 3
open("/usr/lib/locale/en_US.UTF-8/LC_IDENTIFICATION", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_IDENTIFICATION", O_RDONLY) = 3
open("/usr/lib/gconv/gconv-modules.cache", O_RDONLY) = 3
open("/usr/lib/locale/en_US.UTF-8/LC_MEASUREMENT", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_MEASUREMENT", O_RDONLY) = 3
open("/usr/lib/locale/en_US.UTF-8/LC_TELEPHONE", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_TELEPHONE", O_RDONLY) = 3
open("/usr/lib/locale/en_US.UTF-8/LC_ADDRESS", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_ADDRESS", O_RDONLY) = 3
open("/usr/lib/locale/en_US.UTF-8/LC_NAME", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_NAME", O_RDONLY) = 3
open("/usr/lib/locale/en_US.UTF-8/LC_PAPER", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_PAPER", O_RDONLY) = 3
open("/usr/lib/locale/en_US.UTF-8/LC_MESSAGES", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_MESSAGES", O_RDONLY) = 3
open("/usr/lib/locale/en_US.utf8/LC_MESSAGES/SYS_LC_MESSAGES", O_RDONLY) = 3
open("/usr/lib/locale/en_US.UTF-8/LC_MONETARY", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_MONETARY", O_RDONLY) = 3
open("/usr/lib/locale/en_US.UTF-8/LC_COLLATE", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_COLLATE", O_RDONLY) = 3
open("/usr/lib/locale/en_US.UTF-8/LC_TIME", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_TIME", O_RDONLY) = 3
open("/usr/lib/locale/en_US.UTF-8/LC_NUMERIC", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_NUMERIC", O_RDONLY) = 3
open("/usr/lib/locale/en_US.UTF-8/LC_CTYPE", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/en_US.utf8/LC_CTYPE", O_RDONLY) = 3
open(".", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3
		

29.2.1. -o file -- send trace output to FILE instead of stderr

$ strace -o strace.log php --version
$ grep php.ini strace.log
			





原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

目录
相关文章
|
C# C++ Windows
PDMS call Operating System Command
PDMS call Operating System Command eryar@163.com 1.Introduction AVEVA提供了三种二次开发的方式:DARs, PML和AVEVA .Net(C#)。
2195 0
|
1月前
|
Java 应用服务中间件
Process exited with an error: 1 (Exit value: 1) 问题处理
本文介绍了在本地启动项目时遇到“Process exited with an error: 1”错误的解决过程。作者首先排除了配置文件修改的影响,通过分析错误信息,推测为端口占用问题,并使用 `netstat -ano` 命令检查端口占用情况,最终通过终止占用端口的进程解决了问题。
|
7月前
|
前端开发
单步调试报错 Thread 1: EXC_BAD_ACCESS (code=1, address=0x6565656565)
单步调试报错 Thread 1: EXC_BAD_ACCESS (code=1, address=0x6565656565)
153 0
|
7月前
|
C语言 C++
关于DEV中collect2.exe [Error] ld returned 1 exit status的问题解决!!!
关于DEV中collect2.exe [Error] ld returned 1 exit status的问题解决!!!
|
安全 Windows
CRITICAL_PROCESS_DIED
CRITICAL_PROCESS_DIED
4590 2
|
Java
【Java异常】ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2 JDWP exit erro
【Java异常】ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2 JDWP exit erro
381 0
|
存储 运维 Java
Unable to open socket file: target process not responding or HotSpot VM not loaded
在说问题之前,还是那句话,linux 系统一切皆文件。之所以这个错误,那肯定是某些文件有问题。经过查阅相关资料了解到如下: 1.java进程在启动时,在%TEMP%/hsperfdata_%USERNAME%路径下创建进程的临时文件。 %TEMP% 在windows系统中表示 windows的临时目录。一般在C:\Users\用户名\AppData\Local\Temp %TEMP% 在linux 系统中,一般在/tmp目录下
6405 0
collect1:error:ld returned 1 exit status 解决办法
collect1:error:ld returned 1 exit status 解决办法
collect1:error:ld returned 1 exit status 解决办法
|
关系型数据库 Oracle 数据库