如何在Linux中获取进程的进程树跟踪/日志? [英] How to get a process tree trace/log of a process in linux?
问题描述
我想知道脚本以什么顺序启动哪些可执行文件(并以递归方式跟踪这些可执行文件).
I want to know what executables a script launches and in what order (and trace those executables recursively).
例如,假设我在这里有一个bash脚本(称为abc.sh):
For example, let's say I have a bash script here (called abc.sh):
#!/bin/bash
ls
gcc
我想使用跟踪/日志命令"运行此脚本,并获得如下内容:
I'd like to run this script with a "trace/log command" and get something like this:
abc.sh -- ls
|-- gcc -- cpp
-- cc1
... etc.
这表明abc.sh称为ls和gcc.gcc依次称为cpp和cc1.
This show that abc.sh called ls, and gcc. gcc, in turn, called cpp and cc1.
这可能吗?我该怎么做?像上面这样的树视图会很好,但是更简单的视图也可以.
Is this possible? How can I do it? A tree view like the above would be nice, but a simpler view would work as well.
请注意,我不需要进程树的当前快照.相反,我想要跟踪或生成过程的日志.时序注释也将很有用.
Note that I do not want the current snapshot of the process tree. Rather, I want a trace or a log of the spawning processes. Timing annotation would also be useful.
谢谢!
推荐答案
您可以尝试分析 strace
命令的输出.特别是,您将对类似
You may try to analyse the output of strace
command.
Particularly, you'll be interested in something like
strace -f -tt -e trace=execve ./abc.sh
这篇关于如何在Linux中获取进程的进程树跟踪/日志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!