Boost.Process - how to get a process to run a function?

So, I'm trying to do something with Boost.Process , although it has not yet been accepted into the Boost distribution.

The simplest program will look like

#include <boost/process.hpp> 
#include <string> 
#include <vector> 

namespace bp = ::boost::process; 

void Hello()
{
    //... contents does not matter for me now - I just want to make a new process running this function using Boost.Process.
} 

bp::child start_child() 
{ 
    std::string exec = "bjam"; 

    std::vector<std::string> args; 
    args.push_back("--version"); 

    bp::context ctx; 
    ctx.stdout_behavior = bp::silence_stream(); 

    return bp::launch(exec, args, ctx); 
} 

int main() 
{ 
    bp::child c = start_child(); 

    bp::status s = c.wait(); 

    return s.exited() ? s.exit_status() : EXIT_FAILURE; 
} 

How to execute a tall process that I create to execute the Hello () function?

+3
source share
1 answer

You can not. Another process is another executable file. If you do not create another instance of the same program, the child process will not even contain the Hello () function.

, Hello(). std: cin (.. )

UNIX/Linux . . fork (2). Hello() . boost:: process: launch (9 map to fork + exec . fork() boost, , .

, , .

+7

Source: https://habr.com/ru/post/1787310/


All Articles