使用apache thrift通过exec执行二进制文件
Executing Binary via exec using apache thrift
我使用Apache Thrift来设置一个c++服务器。在服务器端,我想执行
execl("a.out","",(char *)NULL);
,但要么先执行上面的代码行,要么先执行server.serve()。有什么方法可以让服务器启动并在服务器上运行代码行吗?
我试着把它放在message_test函数,但我只希望它执行一次,而不是每次当我启动一个客户端。
a.cpp:
int main(){
cout<<"I have started up"<<endl;
string message;
while (cin >> message){
cout<<"your message is: "<<message<<endl;
}
cout<<"I have now exited"<<endl;
}
Server.cpp
class ThforkServiceHandler : virtual public ThforkServiceIf {
public:
ThforkServiceHandler() {
// Your initialization goes here
}
void message_test(const std::string& message) {
// Your implementation goes here
printf("message_testn");
}
};
int main(int argc, char **argv) {
int port = 9090;
shared_ptr<ThforkServiceHandler> handler(new ThforkServiceHandler());
shared_ptr<TProcessor> processor(new ThforkServiceProcessor(handler));
shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);
server.serve();
return 0;
}
根据文档,execl()
用调用的程序替换当前进程。另一方面,server.serve()
将阻塞,直到有人强制服务器退出内部的服务器循环。
这就解释了为什么你只能得到两者中的一个。一个替换服务器,另一个替换调用块。实际上,这两个调用中的任何一个都将(或多或少)是服务器代码中执行的最后一个操作。
我建议使用system()
呼叫或类似的东西来代替。
相关文章:
- 如何忽略某些二进制文件的执行?
- -bash:/a.out:无法执行二进制文件:Exec格式错误
- c ++:如何为每个特征制作特定的二进制文件(可执行文件)?
- 我有一个预处理的 C/C++ 源文件 (cacti.i).如何从这个 .i 文件生成可执行二进制文件,以便我可以像 ./
- 如果在执行过程中替换二进制文件,"const"数组是否驻留在内存中?
- 如何告诉 clang 将调试符号放入可执行二进制文件中
- Docker Centos,无法执行二进制文件
- bash:./main:无法执行二进制文件:Exec格式错误
- 如何直接从分配的内存中执行mmaped二进制文件/代码
- 在运行时动态更新二进制文件(可执行文件)而不停止的任何类型的方法
- 无法使用字符串中的命令使用 execlp() 执行二进制文件
- 从没有外壳的C++执行二进制文件
- 从 Web UI 访问C++编译的可执行二进制文件
- bash:即使二进制和Linux是64位的,也无法执行二进制文件:Exec格式错误
- AWS:无法执行二进制文件
- 从内存执行二进制文件
- PHP - 无法执行 c++ 二进制文件?
- 如何制作不依赖于 .so 文件的可执行二进制文件
- 使用apache thrift通过exec执行二进制文件
- 在linux中使用共享库执行二进制文件