Design a program using ordinary pipes in which one process(e.g., parent process) sends the student’s response to the examdifficulty-rating question to a second process (e.g., childprocess). The second process sends a new message with the student’srating back to the first process. For example, the first processasks the student how s/he rates the difficulty of the exam 1. Then,the first process sends the student’s response to the secondprocess. If the student responds that the exam is ok, the secondprocess sends back the following message to the first process:”>> Exam 1 is just right”.

This will require two pipes:

– One pipe for sending the student’s response from the firstprocess to the second process.

– The other pipe for sending the new message from the secondprocess to the first process.

Below is the output of the program:

How would you rate the difficulty of Exam 1? Enter E for Easy, Ofor ok, H for Hard: O answer: O

easy or hard: just right

child read… >just right<

child is writing…:Exam 1 is just right >> Exam 1 is justright!


// exam_eval.c

// Assignment3_OrdinaryPipes


#include <stdio.h>

#include <unistd.h>

#include <sys/types.h>

#include <string.h>

#define BUFFER_SIZE 100

#define READ_END  0

#define WRITE_END 1

// Function prototypes

char isExamHard(void);

void request_rating(int firstPipe[], int secondPipe[]);

void respond_to_the_rating(int firstPipe[], intsecondPipe[]);

int main(int argc, const char * argv[]) {

  pid_t pid;

  // TODO: Create two pipes

  //    Terminate the program if failto create the pipes


  // TODO: Create a child process

  //    Terminate the program if failto fork a child process


  // TODO: parent process invokes request_rating

  //    child process invokesrespond_to_the_rating


  return 0;



*            isExamHard          *

* This function asks a question about Exam 1 difficulty *


char isExamHard(void)


  char input;

  printf(“How would you rate the difficulty of Exam1?n”);

  printf(“Enter E for Easy, O for ok, H for Hard:”);

  scanf(“%c”, &input);


  return input;



*          request_rating         *

* Asks the student to rate the exam #1, sendsthe  *

* student’s reponse to the second process and reads *

* the message from the childprocess.        *


void request_rating(int *first_pipe, int *second_pipe) {

  char level;

  char write_msg[BUFFER_SIZE];


  level = isExamHard();


  printf(“answer: %cn”, level);

  if ((level == ‘E’) || (level == ‘e’)) {

   strcpy(write_msg, “easy”);


  else if ((level == ‘O’) || (level == ‘o’)) {

   strcpy(write_msg, “just right”);


  else {

    strcpy(write_msg, “hard”);


  printf(“easy or hard: %sn”, write_msg);


  // TODO: write the student’s response to the firstpipe

  // TODO: read the message from the second pipe



*      respond_to_the_rating           *

* Reads the message from the first process and returns *

* the new message with the student’s response to the  *

* first process.                    *


void respond_to_the_rating(int *first_pipe, int *second_pipe){

  // TODO: read the student’s response from the firstpipe


  // TODO: write the new message to the secondpipe