/**************************************/
/*                                    */
/*  Prof. Dr. Carsten Vogt            */
/*  Fachhochschule Koeln              */ 
/*  Fakultaet 07, Nachrichtentechnik  */
/*  http://www.nt.fh-koeln.de/vogt    */
/*                                    */
/*  UNIX-C-Schnittstelle:             */
/*  exit() und wait()                 */
/*                                    */
/**************************************/

#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>

main() {

  int status;

  printf("\n");

  if (fork()==0) {
    sleep(1);
    printf("Sohn: exit(0)\n\n");
    exit(0);
   }


  wait(&status);
  printf("Vater: status = %d\n\n",status);
  printf("Vater: WEXITSTATUS(status) = %d\n\n",WEXITSTATUS(status));

  printf("\n");

  if (fork()==0) {
    sleep(1);
    printf("Sohn: exit(1)\n\n");
    exit(1);
   }


  wait(&status);
  printf("Vater: status = %d\n\n",status);
  printf("Vater: WEXITSTATUS(status) = %d\n\n",WEXITSTATUS(status));

}

