This is a very basic question. The parent process will create some shared memory where it will put two integers in there, then it forked a child which will go to the shared memory and compute the sum of them. All this is fine, but how would the child inform the parent that it’s done computing the sum? Do I need to create a pipe between the two processes to do this? or waitpid() is sufficient to achieve this?
Thank you!
If your child process is no longer needed after computing the sum of your integers, it can return the sum from main and the parent process can retrieve the result using waitpid. In this case, the child would look something like this:
Child process:
If the child process is still needed to do further work for the parent, set up a pipe between the child and parent or arrange some other form of IPC to pass info back and forth.