1 In this assignment you will implement a simulation of the
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 200.) (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 10 I/O operations.
DOIO:
DOIO will collect and 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 10 system calls to initiate I/O operations
DOIO will create 10 IORB
Project Direction
You will write the program C-- 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…
Here is my code from project 1:
semaphore full;
semaphore empty;
semaphore count;
semaphore mutex = 1;
int buffer[5];
int MAX = 20;
int i;
int j;
int prod = 0, consum = 0;
void producer()
{
for(i = 0; i < MAX; i++)
{
p(empty);
p(mutex);
prod = i % 2;
cout << \"Put \" << i << \" into buffer\" << endl;
buffer[prod] = i;
prod = prod + 1;
v(mutex);
v(full);
v(count);
}
}
void consumer()
{
for(j = 0; j < MAX; j++)
{
p(full);
p(mutex);
cout << \"Get \" << buffer[consum] << \" from buffer\" << endl;
v(mutex);
v(empty);
p(count);
}
}
void main()
{
initialsem(full, 0);
initialsem(empty, 5);
initialsem(count, 0);
cobegin
{
producer();
consumer();
}
}
The question is that its asking to write the program in C-- based on the programming from project one, how would i transition or even start, any help will do, thank you in advance!
Solution
Hi , firstly for writing a Program in \'C\' we need to include certain input/output library files in our Program.
U can start with the below statement -
#include<stdio.h>
#include
//above is the library file to be included
//declaration and initializing the varialbles
int buffer[5];
int MAX = 20;
int i,j;
int prod = 0, consum = 0;
//method producer
void producer()
{
for(i = 0; i < MAX; i++)
{
p(empty);
p(mutex);
prod = i % 2;
printf << \"Put \" << i << \" into buffer\" << endl;
//printf - for printing an output on screen in \'C\'.
buffer[prod] = i;
prod = prod + 1;
v(mutex);
v(full);
v(count);
}
}
//method consumer
void consumer()
{
for(j = 0; j < MAX; j++)
{
p(full);
p(mutex);
cout << \"Get \" << buffer[consum] << \" from buffer\" << endl;
v(mutex);
v(empty);
p(count);
}
}
//main function
void main()
{
// if the code \'initialsem with diferent parameters refers to file operations, then the below can be used in \"C\".
Pointers needs to be used -
File *fp;
char ch;
fp = fopen(\"one.txt\", \"w\");
printf(\"Enter data\");
while( (ch = getchar()) != EOF) {
putc(ch,fp);
}
fclose(fp);
fp = fopen(\"one.txt\", \"r\");
while( (ch = getc(fp)! = EOF)
printf(\"%c\",ch);
fclose(fp);
}
producer();
consumer();
}
//As semaphores can be used in \'C\', have not updated those statements, as above.
//Please see if this clears your question



