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.)
Kill a process started with popen
ckillmultithreadingpopen
Related Topic
- How to initialize all members of an array to the same value
- Python – ny way to kill a Thread
- Linux – What killed the process and why
- Sqlite – Improve INSERT-per-second performance of SQLite
- C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming
- What does the ??!??! operator do in C
- Ubuntu – How to kill a process on a port on ubuntu
Best Answer
Don't use
popen()
, write your own wrapper that does what you'd like.It's fairly straightforward to
fork()
, and then replacestdin
&stdout
by 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.