How to get a process tree trace/log of a process in linux?

独自空忆成欢 提交于 2021-02-08 03:39:29

问题


I want to know what executables a script launches and in what order (and trace those executables recursively).

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.

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.

Thanks!


回答1:


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



回答2:


You can use pstree command. It was conceived to show exactly what you are looking for: process tree (hence the name, pstree). It won't give you process tracing, but you could call it multiple times to get something similar to what you're looking fOr.



来源:https://stackoverflow.com/questions/3938266/how-to-get-a-process-tree-trace-log-of-a-process-in-linux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!