After opening a pipe to a process with popen, is there a way to kill the process that has been started? (Using pclose is not what I want because that will wait for the process to finish, but I need to kill it.)
After opening a pipe to a process with popen , is there a way
Share
Don’t use
popen(), write your own wrapper that does what you’d like.It’s fairly straightforward to
fork(), and then replacestdin&stdoutby usingdup2(), and then callingexec()on your child.That way, your parent will have the exact child PID, and you can use
kill()on that.Google search for ‘popen2() implementation’ for some sample code on how to implement what
popen()is doing. It’s only a dozen or so lines long. Taken from dzone.com we can see an example that looks like this:NB: Seems like popen2() is what you want, but my distribution doesn’t seem to come with this method.