#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

int main() {
   pid_t pids[3];
   int i;
   for (i=0; i<3; ++i) {
      pids[i]=fork();
      if (pids[i]==-1) {
         perror("fork");
         exit(EXIT_FAILURE);
      }
      if (pids[i]==0) {
         // child
         printf("child  %d %d %d\n", i, getppid(), getpid());
      }
      else {
         // parent
         printf("parent %d %d %d\n", i, getppid(), getpid());
         waitpid(pids[i], NULL, 0);
      }
   }
   return EXIT_SUCCESS;
}
