Ç - 获取PID的进程打开的popen [英] C - Get PID of process opened with popen

查看:415
本文介绍了Ç - 获取PID的进程打开的popen的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用C编写的程序,打开用popen另一个程序。我想获得该程序或某些类型的处理程序,它的PID,从而在一定时限后,将其杀死,或者如果它超过一定的RAM,和stdout限制。我想,这一定与ptrace的,它需要的PID,我不知道如何获得工作要做。

I have a program written in C, which opens another program using popen. I 'd like to get the pid of that program or some kind of handler for it, so as to kill it after a certain time limit, or if it exceeds some ram, and stdout limits. I think this must be done with ptrace, which needs the PID, which I don't know how to obtain.

推荐答案

只写你自己的实现的popen 的返回的PID。它的丑陋远远小于围绕现有的popen 一些疯狂的两轮牛车。你可以找到源头code到的popen 实现全网。 这里有一个

Just write your own implementation of popen that returns the PID. It's much less ugly than some crazy hackery around the existing popen. You can find source code to popen implementations all over the net. Here's one.

这篇关于Ç - 获取PID的进程打开的popen的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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