如何从LinuxOS中的python脚本运行/停止c程序?

bat*_*man 3 c++ python gcc g++

我有ac程序基本上是在无限While循环中运行,如下所示.

int main(int argc, char** argv )
{    
     Detectdirection *d;
     //Mosquitto
     io_service io;
     deadline_timer t(io);
     MosquitoInterface *m = new MosquitoInterface(t);



     d = new Detectdirection();      
     while(true)
     {        
        int ret =  d->Tracking();
        if(ret < 0)
           cout << "Pattern is not found" << endl ;
     }  
     delete d;
     delete m;
     cout << "Exit" << endl;
     return 0;
}
Run Code Online (Sandbox Code Playgroud)

我喜欢从python脚本运行和停止程序.运行程序非常简单.所讨论的只是提供一个路径构建文件在这里.

但是如何从Pyhton中停止应用程序,以便正确删除创建的对象.

Lan*_*ing 5

您需要在进程之间进行通信.

向进程发送信号(并在可执行文件中捕获该信号)是执行此操作的常用方法.

从python发送信号:如何终止使用shell = True启动的python子进程

处理信号: C中的信号处理

或者,您可以使用更高级的技术来发送消息(例如zeromq 了解ZeroMQ,dbus /sf/ask/tagged/dbus/,或COM COM,COM +,DCOM,从哪里开始?)

这里的关键字是进程间通信.它有自己的维基百科文章https://en.wikipedia.org/wiki/Inter-process_communication