c++ - Linux, share a buffer with another program in fork() -
i have client/server model each client can send task server - called task requesting.
this base simple distributed-computing library after.
"in other words, if ordinary application processes array of independent elements, in data-parallel model, each processor assigned process part of array. support data-parallel computing, core library should divide tasks parts, transfer task data local memory of particular cpu, run task on cpu, transfer results caller, , provide ability request global data caller."
- a task binary(std::vector uint8_t) , payload(std::vector uint8_t).
- a binary compiled task / application.
- a payload optional data serialized uint8_t.
so simply:
class cgridtask { public: ... bool run (); private: std::vector<uint8_t> m_vbinary; std::vector<uint8_t> m_vpayload; uint32_t m_uiuniqueid; ... }
the pseudo-diagram shows how 'works':
[client1]---[send task payload: integer value = 10]-->[server] [server]-->[run task payload] [task, start] [task, calculate...] [task, calculate...] [task, calculate...] [task, integer value = 10 + new value] [task, return] [server]-->[send task client1]
ok, when server calls:
pgridtask->run();
here should happen:
bool cgridtask::run() { // dump binary temporary file dump(m_vbinary); // chmod +x system("chmod +x " + strtempoprarybinaryname); // run binary , pass m_vpayload ...how can this?... // return true if binary executed return true; }
the problem here share m_vpayload executed binary... how can this?
thank input this!
as alternative other solutions, , depending on how child process structured, communicate child process through pipes (the usual pipe/fork/dup2/exec
pattern).
sure performance worse shared memory, whole architecture more flexible, , various programs less coupled: child's point of view, takes data stdin
, outputs results stdout
makes reusable in other contexts (and makes easy reuse "ordinary" interactive programs in context of task server without having adapt them first).
Comments
Post a Comment