如何找到所有子进程? [英] How to find all child processes?

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

问题描述

在我的工作在一台基于Linux的项目,我需要能够找到我所有的子进程。它不是记录每一个被启动时可行 - 他们需要的事实之后被发现。这需要纯C,我想做到这一点不读的/ proc。有谁知道如何做到这一点?

In a Linux-based project that I am working on, I need to be able to find all of my child processes. It is not feasible to record every time one is started -- they need to be found after the fact. This needs to be pure C, and I'd like to do it without reading /proc. Does anyone know how to do this?

推荐答案

我看到你的评论,这是不记录进程的创建为奇数可行的,但如果你真的不能(可能是因为你不知道知道有多少人会被创建,不希望有保留的realloc ING内存),那么我可能会打开所有符合水珠的文件的的/ proc / [1-9] * /状态并查找说 PPID线:其中,民> ,其中< NUM方式> 是我的进程id

I find your comment that it is not feasible to record the creation of processes to be odd, but if you really can't (possibly because you don't know how many will be created and don't want to have to keep reallocing memory), then I would probably open all of the files that match the glob /proc/[1-9]*/status and look for the line that says PPid: <num> where <num> was my process id.

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

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