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.
Share
Just write your own implementation of
popenthat returns the PID. It’s much less ugly than some crazy hackery around the existingpopen. You can find source code topopenimplementations all over the net. Here’s one.