System call how to make parent wait for child

Solution 1:

Waiting for the child works. However, your expectations are wrong.

Apparently you think that computations in the child process after the fork are visible in the parent process. They are not. The child is a new copy of the parent program at the time of fork. At that time, the parent's sum is 0 and stays that way.

There are several mechanisms to pass data from child to parent (the search term is interprocess communication, IPC).

  • exit() status
  • files
  • shared memory
  • pipes
  • signals
  • message queues
  • anything else I have missed