如何获得的PID所有派生子进程的ID在Linux下C [英] How to get all descendent child process id of pid in c in linux

查看:742
本文介绍了如何获得的PID所有派生子进程的ID在Linux下C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我和子进程则 EXEC 和创造更多的子进程(这本身可以创造更多的流程),我怎么从第一道工序?

If I fork and the child process then exec and creates more child processes (which themselves can create more processes) , how do I get a list of pids of all the descendent process from the first process?

有没有更好的方法,然后循环虽然的/ proc / 和检查 PPID (进程的ID父)每个进程的

Is there a better way then looping though /proc/ and checking the PPid (the parent of process's id) of each of process?

推荐答案

通过的/ proc迭代是标准的方式来做到这一点。那怎么 PS 和朋友( pstree 等)来实现。

Iterating through /proc is the "standard" way to do this. That's how ps and friends (pstree, etc.) are implemented.

这篇关于如何获得的PID所有派生子进程的ID在Linux下C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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