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

前端 未结 1 1147
礼貌的吻别
礼貌的吻别 2021-01-14 09:02

So I try to do something with Boost.Process though it has not been accepted into the Boost distribution yet.

simpliest programm would look like

#inc         


        
相关标签:
1条回答
  • 2021-01-14 09:54

    You can't. Another process is another executable. Unless you spawn another instance of the same program, the child process will not even contain the Hello() function.

    If the child is another instance of your program, you need to define your own way to tell the child to run Hello(). That could be process arguments or some protocol on std:cin (i.e. using standard input for inter-process communication)

    On a UNIX/Linux platform you can start another process and NOT run a different executable. See the fork(2) system call. Then you can call Hello() in the child. But boost::process:launch(9 map to fork+exec on such platforms. Plain fork() is not exposed by boost, for example because it doesn't exist on other platforms.

    There may be extremely platform-dependent ways to do what you want, but you don't want to go there.

    0 讨论(0)
提交回复
热议问题