/**
 * File: zombie.c
 * ------------------
 * Novelty program to illustrate how zombies work.
 * Created by Roz.
 */

#include <stdio.h>        // for printf
#include <unistd.h>       // for fork, getpid, getppid
#include <sys/wait.h>
#include "exit-utils.h"   // for our own exitIf

static const int kForkFailed = 1;

int main(int argc, char *argv[]) {
  printf("Currently running process: %d\n", getpid());
  
  pid_t pid = fork();
  exitIf(pid == -1, kForkFailed, stderr, "fork function failed.\n");
  
  if (pid == 0) { // in child
    printf("Child process (pid=%d) exiting.\n", getpid());
    exit(0); // terminate child
  } else { // in parent, which reaps its child
    int status;
  	waitpid(pid, &status, 0);
    
    sleep(60);
  }

  return 0;
}