Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1.- In this assignment you will implement a simulation of the interaction of user programs with the OS to execute an I/O operation. User programs:

1.- In this assignment you will implement a simulation of the interaction of user programs with the OS to execute an I/O operation.

User programs:

User programs will communicate with DOIO (OS) to request an I/O operation. (this will simulate a system call)

User programs will give to DOIO two parameters: User id and an address (addr is a random number in the range 1 and 20.) (addr is an integer that represents a track number in the hard drive).

User programs will pass the parameters to DOIO through two buffers of size one each (bufid and bufaddr).

Once the parameters are stored in the buffers, user programs executes a P(request served) operation to wait for the completion of the I/O operation.

There will be one user running concurrently and it will execute 5 I/O operations.

DOIO:

DOIO will collect an id and address(addr) from bufid and bufaddr to assemble the IORB.

DOIO will store the IORB (id and addr) into two buffers that represent the IORQ (iorqid and iorqaddr).

Device driver:

Device driver will collect an IORB (pair id and addr) from iorqid and iorqaddr and then initiates the physical I/O operation on the hard drive and wait for the I/O operation to be completed: P(operation complete).

The device driver initiate the physical I/O operation by storing addr into a buffer of length one. The buffer name is pio (physical I/O).

When the I/O operation completes a signal is received, the driver will identify the user that issued the I/O request using the id, and will signal the semaphore request served associated to the user.

Disk:

The disk process simulates the access to a track in the hard drive.

The Disk process gets the addr from pio and stores it in a variable called seek and iterates in a dummy loop from 1 to seek.

Once out of the loop, disk will execute a V on the semaphore operation complete

Define all semaphores that you need according to the number of buffers used.

The user will make 5 system calls to initiate I/O operations

DOIO will create 5 IORB

Project Direction

You will write a C-- program based on the BACI interpreter that you used in programming project 1.

Test your solution

You must run and test your solution and comment on the results emitted.

Project Submission

What to submit?

Submit the source code(.cm file) and the output file showing the results:

Example for the print out of results:

User 1 executes system call SIO or DOIO

DOIO assembles IORB and inserts it in IORQ

Driver initiates I/O operation for user 1

Disk Completes I/O operation (disk does not know what process initiated the I/O operation)

Driver signal user 1 (operation complete)

User 1 executes system call SIO or DOIO

DOIO assembles IORB and inserts it in IORQ

And so on

My current code is:

semaphore full; semaphore empty; binarysem mutex;

const int size = 5; int buffer[size];

int in = 0; int out = 0; int itemProduced = 0; int itemConsumed = 0; int producer = 0; int consumer = 0; int itemCounter = 1; int i = 0;

void Produce(){ int item;

while (producer == 0){

if (itemProduced == 20){ producer = 1; break; }

else{ item = itemCounter; itemCounter = itemCounter + 1;

p(full); p(mutex);

if(itemProduced < 20){

cout << "Item " << item << " produced" << endl;

buffer[in]= item; in = (in + 1) % size; itemProduced = itemProduced + 1;

if (itemProduced >= 20){ producer = 1; v(mutex); v(empty); break; }

}

v(mutex); v(empty);

} }

}

void Consume(){ int item;

while (consumer == 0){

if (itemConsumed == 20){ consumer = 1; v(empty); break; }

else{ p(empty); p(mutex);

if (itemConsumed != 20){ item = buffer[out]; itemConsumed = itemConsumed + 1;

cout << "Item " << item << " consumed." << endl;

out = (out + 1) % size;

if (itemConsumed == 20){ consumer = 1; v(mutex); v(empty); break; } }

v(mutex); v(full);

} } }

void main(){ initialsem (full,size); initialsem (empty,0); initialsem (mutex,1);

cobegin{ Produce();Consume(); }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Spomenik Monument Database

Authors: Donald Niebyl, FUEL, Damon Murray, Stephen Sorrell

1st Edition

0995745536, 978-0995745537

More Books

Students also viewed these Databases questions

Question

Describe an example in which you would want to use a derived table.

Answered: 1 week ago