Hi everybody,
I was wondering how I can kill a process started with system(cmd) within a thread.
For example I start a new process (another c++ program fi) from a thread like this:
class SystemThread: public ofThread{
public:
string cmd;
void setup(string _cmd){
this->cmd = _cmd;
}
void threadedFunction(){
if (isThreadRunning()){
system(cmd.c_str());
}
};
in main.h
#include "SystemThread.h"
...
SystemThread systhread;
in main.cpp
void ofApp::setup(){
string execpath = ofToDataPath("ThisIsAnotherProgram_FFMPEG_FI");
string cmd="bash --login -c '";
cmd += execpath;
cmd += "'";
systhread.setup(cmd);
systhread.startThread();
//continue with other stuff here
}
What I have now is a simple program that is running in the shell. (this could be ffmpeg fi coverting some files)
What I would like to know is, how to kill this running process when I stop the thread. I have tried to use popen en pclose but using pclose freezes everything...
I know it works when I look at the multiple ffmpeg video recorders out there (fi https://github.com/timscaffidi/ofxVideoRecorder), but I don't understand quite well how they manage to start/stop the ffmpeg process.
Maybe it has something to do with opening/closing the pipe that makes ffmpeg stop? I am not sure what is going on exactly.
I am looking for a general solution to do this, not only ffmpeg related, but I am a bit in the dark here.
Thank you for your help in advance,