#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>

int main(){
         pid_t  pid;
	 int status;
	 pid_t s;
        /* fork another process */
	pid = fork();
	if (pid < 0) { /* error occurred */
		fprintf(stderr, "Fork Failed");
		exit(-1);
	}
	else if (pid == 0) { /* child process */
	  //Overlay address space with UNIX command "ls"
	  printf("child pid = %d\n", getpid());
          if(execl("/bin/ls", "ls", "-la", NULL) < 0){
	     printf("Command not found\n");
             exit(1);
          }
	  exit(0);
	}
	else { /* parent process */
	  /* parent will wait for the child to complete */
	  
          printf("#####I am the parent#######\n");
           s = wait (&status);
          if(s != -1)
             printf("Parent detect child process # %d is done\n", s);          
	 
	 }
         return 0;
}

