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

int main () {
    int pid1, pid2, status1, status2, child1, child2;
    pid1 = fork(); 
    if (pid1<0) {
        printf ("Fork operation was uncussesfull\n");
        return -1 ; }
    else if (pid1>0) {
          printf ("Parent process with pid %d and ppid %d \n",getpid(), getppid());
          child1 = wait(&status1);
          printf ("Child with code %d has beem terminated\n", child1);
          }
    else {
            printf ("Child1 with pid %d kai ppid %d \n", getpid(), getppid());
            pid2 = fork(); 
            if (pid2>0)
              {
                printf ("Parent process (child1) for child2\n");
                child2 = wait(&status2);
                printf ("Child with code %d has been terminated\n", child2); }
           else {
                printf ("Child2 with pid %d and ppid %d \n", getpid(), getppid());
                printf ("Calling pwd command...");
                execl ("/usr/bin/pwd","pwd",NULL); }
            
            printf ("Creating a new directory...\n");
            execlp ("mkdir", "mkdir", "OSLab", NULL); }}
