2015-10-22 15:00:05 +08:00
|
|
|
# strace
|
2015-03-21 01:01:05 +01:00
|
|
|
|
2016-01-07 18:31:27 +01:00
|
|
|
> Troubleshooting tool for tracing system calls.
|
2022-03-22 03:07:48 +10:00
|
|
|
> More information: <https://manned.org/strace>.
|
2015-03-21 01:01:05 +01:00
|
|
|
|
2025-03-19 00:36:34 +02:00
|
|
|
- Start tracing a specific process by its PID:
|
2015-03-21 01:01:05 +01:00
|
|
|
|
2025-03-13 04:41:47 +02:00
|
|
|
`strace {{[-p|--attach]}} {{pid}}`
|
2015-03-21 01:01:05 +01:00
|
|
|
|
2025-03-19 00:36:34 +02:00
|
|
|
- Trace a process and filter output by system call [e]xpression:
|
2015-03-21 01:01:05 +01:00
|
|
|
|
2025-03-13 04:41:47 +02:00
|
|
|
`strace {{[-p|--attach]}} {{pid}} -e {{system_call,system_call2,...}}`
|
2015-03-21 01:01:05 +01:00
|
|
|
|
2016-01-07 18:31:27 +01:00
|
|
|
- Count time, calls, and errors for each system call and report a summary on program exit:
|
2015-03-21 01:01:05 +01:00
|
|
|
|
2025-03-13 04:41:47 +02:00
|
|
|
`strace {{[-p|--attach]}} {{pid}} {{[-c|--summary-only]}}`
|
2016-01-04 03:17:07 +09:00
|
|
|
|
2025-03-13 04:41:47 +02:00
|
|
|
- Show the time spent in every system call and specify the maximum string size to print:
|
2016-01-04 03:17:07 +09:00
|
|
|
|
2025-03-13 04:41:47 +02:00
|
|
|
`strace {{[-p|--attach]}} {{pid}} {{[-T|--syscall-times]}} {{[-s|--string-limit]}} {{32}}`
|
2016-08-22 07:59:39 -04:00
|
|
|
|
2018-01-01 21:06:51 +05:30
|
|
|
- Start tracing a program by executing it:
|
2016-08-22 07:59:39 -04:00
|
|
|
|
|
|
|
`strace {{program}}`
|
2017-12-07 20:16:57 +01:00
|
|
|
|
|
|
|
- Start tracing file operations of a program:
|
|
|
|
|
|
|
|
`strace -e trace=file {{program}}`
|
2024-02-20 01:28:47 +11:00
|
|
|
|
2025-03-13 04:41:47 +02:00
|
|
|
- Start tracing network operations of a program as well as all its forked and child processes, saving the output to a file:
|
2024-02-20 01:28:47 +11:00
|
|
|
|
2025-03-13 04:41:47 +02:00
|
|
|
`strace {{[-f|--follow-forks]}} -e trace=network {{[-o|--output]}} {{trace.txt}} {{program}}`
|