跟踪根进程产生的所有子进程 [英] tracking all child process spawned by a root process

查看:60
本文介绍了跟踪根进程产生的所有子进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在检查某个运行编译器的 make 系统.我想跟踪由这种根"进程产生的所有子进程.

I'm inspecting a certain make system that runs compilers. I want to track all child processes ever spawned by such a "root" process.

我知道有 ps 命令,因为我是 Python 用户,所以使用 psutil 包.但我不确定我是否会错过调用之间的一些短暂进程.

I'm aware there's the ps command and as I'm a Python user, the psutil package. But I'm not sure if I'll miss some short lived processes between the calls.

我认为我真正想要的是类似于 inotify(或 Python 中的 watchdog),但它不是跟踪目录,而是跟踪所有子进程活动.

I think what I really want is something like inotify (or watchdog in Python), but instead of tracking directory, it tracks all child process activity.

是否有这样的系统调用,或者最好是 Python 包,可以做到这一点?

Is there such a system call, or preferably, package of Python, that does this?

提前致谢.

推荐答案

sttace 可以提供该信息.但是您可能需要解析输出才能获得您感兴趣的信息.

sttace can provide that info. But you may have to parse the output to get just the info you are interested in.

strace -f -e trace=process <executable>

这将跟踪 的所有子进程,并且只会跟踪与进程相关的系统调用(本质上是 waitforkcloneexec).

That will trace all child processes of <executable> and will trace only the process related syscalls (essentially wait, fork, clone and exec).

这篇关于跟踪根进程产生的所有子进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆