Linux系统工具:strace

本文最后更新于:2022年9月4日 下午

系统调用简介

进程通过系统调用使用内核服务。系统调用会进入内核,让内核执行服务然后返回
在这里插入图片描述

一些常见的系统调用:

系统调用 描述
fork() 创建进程
exit() 结束当前进程
wait() 等待子进程结束
exec(filename, *argv) 加载并执行一个文件
open(filename, flags) 打开文件,flags 指定读/写模式
read(fd, buf, n) 从文件中读 n 个字节到 buf
write(fd, buf, n) 从 buf 中写 n 个字节到文件
close(fd) 关闭打开的 fd
unlink(filename) 删除文件

strace的常见用法

strace可以使你在不知道程序源代码的情况下跟踪应用程序的系统调用

让我们打开tldr查看strace的常见用法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Troubleshooting tool for tracing system calls.
More information: https://manned.org/strace.

- Start tracing a specific process by its PID:
strace -p pid

- Trace a process and filter output by system call:
strace -p pid -e system_call_name

- Count time, calls, and errors for each system call and report a summary on program exit:
strace -p pid -c

- Show the time spent in every system call:
strace -p pid -T

- Start tracing a program by executing it:
strace program

- Start tracing file operations of a program:
strace -e trace=file program

打印出运行echo wdnmd 过程的系统调用:
在这里插入图片描述


Linux系统工具:strace
http://gls.show/p/d936e762/
作者
郭佳明
发布于
2022年9月4日
许可协议