Skip to the content.

strace 基本使用

strace 可以监控的内容:

To trace child processes, -f option need to be specified 1

strace -c ls # stat
strace -w -c ls # wall time
strace -c -S calls ls # sort by calls

-e expression 是一个强大的工具,可以控制输出的详细程度,约束到底跟踪哪一个东西,操控信号,注入 syscall 返回值

strace 执行的时候,可以修改执行的 trace 以及 修改指令执行的位置。

-I interruptible 用于屏蔽信号

常见操作

重定向到文件

strace -o a.log ls

attach 到一个进程上

过滤掉特定的 syscall

#!/usr/bin/env bash
strace -e 'trace=!read,writev' tcpdump -A -s0 port 80

跟踪和文件相关的调用

sudo strace -f -t -e trace=file ls

仅仅跟踪一个系统调用

strace -e trace=openat fio /home/martins3/core/vn/docs/kernel/code/aio/4k-read.fio

https://news.ycombinator.com/item?id=38908496

扩展阅读

graftcp 比 proxychain-ng 的好处在于,前者用的 ptrace 后者是截获动态库, 所以 graftcp 可以代理任何程序。 https://github.com/hmgle/graftcp

除了比 strace 好看,还有什么作用来着?

https://github.com/sectordistrict/intentrace

strace 实现原理

http://arthurchiao.art/blog/how-does-strace-work-zh/

本站所有文章转发 CSDN 将按侵权追究法律责任,其它情况随意。

  1. strace little book