You should wait until all the child completes their tasks put following code in parent side.
printf("Parent process started.n");
if ((pid = wait(&status)) == -1)
/* Wait for child process. */ */
perror("wait error");
else { /* Check status. */
if (WIFSIGNALED(status) != 0)
printf("Child process ended because of signal %d.n",
WTERMSIG(status));
else if (WIFEXITED(status) != 0)
printf("Child process ended normally; status = %d.n",
WEXITSTATUS(status));
else
printf("Child process did not end normally.n");
}
printf("Parent process ended.n");