Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem : Inter Process Communication using Shared Memory (C Programming) In Linux, a parent process passes information to its child since the child receives a

Problem : Inter Process Communication using Shared Memory (C Programming) In Linux, a parent process passes information to its child since the child receives a copy of its address space. However, in its raw form, the parent does not have any way access to the childs address space. In this part of the assignment, you will create a program in which a driving school instructor instructs its student on what to do in various situations through Shared Memory. The student may encounter the following 5 situations stored in an array of strings: Situations:

a) The light is turning green

b) There is a pedestrian in front of me

c) The car in front of me just stopped

d) The car in front of me is moving

e) The road is turning to the right The teachers recommendation for each situation is, respectively: Recommandations:

a) Press the accelerator

b) Press the break

c) Press the break

d) Press the accelerator

e) Steer right

The student can then do the correct thing or not: Action:

when instructed to press the accelerator, s/he may do the correct thing and respond: Done or do the wrong thing and respond: Oops, I pressed the break instead; when instructed to press the break, s/he may do the correct thing and respond: Done or do the wrong thing and respond: Oops, I pressed the accelerator instead; when instructed to steer right, s/he may do the correct thing and respond: Done or do the wrong thing and respond: Oops, I steered left.

Your program should work as follows: The parent process (the teacher) creates three arrays of strings called Situation, Recommendation and Action, respectively. I should also create a shared memory region that will contain 1) the index of the situation, recommendation or action that will be shared between the teacher and the student; 2) (a) boolean flag(s) to coordinate the order in which the processes should proceed. It should then create a child (the student) process that maps this shared memory region into its address space. The teacher then waits until the student signals that it is ready. After mapping the shared memory region into its address space, the student selects, at random, the situation it will face. It writes the index of that situation in the shared memory region and prints it to the terminal. It then updates the flag(s) to signal to the teacher that it is ready for a recommendation. When its turn comes, the teacher reads the index of the situation and makes the proper recommendation. It writes the index of the proper recommendation in the shared memory region and prints it to the terminal. It then updates the flag(s) to signal to the child that it is ready. From then on, the teacher waits for the student to take action and terminate. Whether the student takes the correct or incorrect action is determined at random. Once chosen, the student writes the index of its action in the shared memory region and prints that action. It then terminates. Upon the students termination, the teacher prints What a good teacher I am! or What a lousy teacher I am! depending on the action chosen by the student. The output should look something like:

Student: The car in front of me just stopped

Teacher: Press the break

Student: Oops, I pressed the accelerator instead

Teacher: What a lousy teacher I am!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions