program to perform the following tasks using system calls:

0
3

i) Parent process should create a child process

ii) Both parent child processes should display their pid and parent’s pid; parent process should also its child’s pid

iii) Load a new program into child process

iv) The parent process should terminate after the child process terminates B. Write a program that implements solution to Producer – Consumer problem using mutex and semaphores.

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


void main(){
	
	pid_t child_pid, wait_pid, parent_pid;
	
	child_pid = fork();
	
	if (child_pid<0){
		printf("Fork Failed\n");
		exit(0);
	}
	
	if (child_pid==0){
		printf("[CHILD] My PID is: %d\n", getpid());
		printf("[CHILD] My Parent's PID is: %d\n", getppid());
		
		printf("[CHILD] I am executing another program now...\n");
		execlp("pwd","pwd",NULL);
	}
	else{
		printf("[PARENT] My PID is: %d\n", getpid());
		printf("[PARENT] My Child's PID is: %d\n", child_pid);
		
		printf("[PARENT] I am waiting for child to terminate...\n");
		wait_pid = wait(NULL);
		
		printf("[PARENT] My child process (PID:%d) has terminated\n", wait_pid);
		printf("[PARENT] Even I am terminating now...\n");
	}
}