I got few problems in Process creation and IPC in Solaris using C++.
This is my problem in a nutshell.
--I do have main process ---> A (say)
---And I want to create child processes of A which are doing independent tasks.
(say C1, C2, C3, ....etc)
Interface of A
------CreateChild(int childID);
------SendMessage(int childID, string str);
------TerminateChild(int childID);

---There sholud be a method to create processes (say) CreateChild(int childID)
---After createing a child process we sholud be able to send messages to channel processes using SendMessage(int childProcessID); messge should go to that particular id that is given. After sending message we have to get reply to that one as well.(Here there can be replies from many processes ; they are identified by child Process No.
-----The problem that I have is if I use fork() with in the main processes the all the methods that are specified in main processes (A) is duplicated in to all the child processes. And each time I called a method in A...That will called with in the child processes as well. So how organized the system inorder to avoid this..

11 Years
Discussion Span
Last Post by Salem

Well if you do

pid = fork();
if ( pid == 0 ) {
  // in child, do child specific stuff
} else if ( pid != -1 ) {
  // in parent, do parent specific stuff
} else {
  // in parent, but fork failed

Then you can separate the parent code from the child code.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.