Operating System Assignment - II2023-24 - IT B V SEMESTER
Operating System Assignment - II2023-24 - IT B V SEMESTER
Process 1 2 3
RES A 2 2 1
RES B 1 1 2
RES C 1 1 0
RES D 1 0 0
RES E 1 1 2
{ int
field1;
int field2;
};
(a) Producer: struct shmem_structure *shptr = get_shared_memory_structure();
while(1)
{
int produced = produceNext();
}
(b) Consumer: struct shmem_structure *shptr = get_shared_memory_structure();
while(1)
{
int consumed; //fill this value from producer consumeNext(consumed);
}
4 Write a P-Threads program that performs matrix multiplication. Specifically use tow matrices A 1 3
and B.
A:MXK and B:KXN.The entry in matrix C for row i column j (C i,j) is the sum of the products of
elements for row I in matrix A and column j in matrix B. Calculate each element in (C i,j) in a
sepatate thread. This will involve creating MXN threads. a)Is the current allocation state is safe
b)Would the following requests be granted in the current state?
i)Process P1 requests (1,1,0)
ii)Process P3 requests (0,1,0)
iii)Process P2 requests (0,1,0)
5 3 3
VASAVI COLLEGE OF ENGINEERING
DEPARTMENT OF INFORMATION TECHNOLOGY
B.E V SEMESTER, ACADEMIC YEAR: 20223-24 IT- B
Name of the Instructor: Leelavathy B
ASSIGNMENT – II
Name of the Course: OPERATING SYSTEMS
Date of issue: 15.12.2023
Max. marks: 5
Last date of submission: 29.12.2023
Format of submission: Report Format, Hardcopy
Note: CaseStudy is common for every one
2 Consider a clinic with one doctor and a very large waiting room (of infinite capacity). Any patient 1 3
entering the clinic will wait in the waiting room until the doctor is free to see her. Similarly, the the
doctor also waits for a patient to arrive to treat. All communication between the patients and the
doctor happens via a shared memory buffer. Any of the several patient processes, or the doctor
process can write to it. Once the patient “enters the doctors office”, she conveys her symptoms to
the doctor using a call to consultDoctor(), which updates the shared memory with the patient’s
symptoms. The doctor then calls treatPatient() to access the buffer and update it with details of the
treatment. Finally, the patient process must call noteTreatment() to see the updated treatment details
in the shared buffer, before leaving the doctor’s office. A template code for the patient and doctor
processes is shown below. Enhance this code to correctly synchronize between the patient and the
doctor processes. Your code should ensure that no race conditions occur due to several patients
overwriting the shared buffer concurrently. Similarly, you must ensure that the doctor accesses the
buffer only when there is valid new patient information in it, and the patient sees the treatment only
after the doctor has written it to the buffer. You must use only semaphores to solve this problem.
Clearly list the semaphore variables you use and their initial values first. Please pick sensible names
for your variables.
(a) Semaphore variables and initial values:
(b) Patient process: consultDoctor(); noteTreatment();
(c) Doctor process:
while(1)
{
treatPatient();
}
3 Provide two programming examples in which multi threading provided better performance than a 3 3
single threaded solution
4 1 3
5 Give an example of race condition in which only one process writes to any share data 3 3
VASAVI COLLEGE OF ENGINEERING
DEPARTMENT OF INFORMATION TECHNOLOGY
B.E V SEMESTER, ACADEMIC YEAR: 20223-24 IT- B
Name of the Instructor: Leelavathy B
ASSIGNMENT – II
Name of the Course: OPERATING SYSTEMS
Date of issue: 15.12.2023
Max. marks: 5
Last date of submission: 29.12.2023
Format of submission: Report Format, Hardcopy
Note: CaseStudy is common for every one
5 3 3
VASAVI COLLEGE OF ENGINEERING
DEPARTMENT OF INFORMATION TECHNOLOGY
B.E V SEMESTER, ACADEMIC YEAR: 20223-24 IT- B
Name of the Instructor: Leelavathy B
ASSIGNMENT – II
Name of the Course: OPERATING SYSTEMS
Date of issue: 15.12.2023
Max. marks: 5
Last date of submission: 29.12.2023
Format of submission: Report Format, Hardcopy
Note: CaseStudy is common for every one
Here, wants1 and wants2 are shared variables, which are initialized to false. Which one of the
following statements is TRUE about the above construct?
VASAVI COLLEGE OF ENGINEERING (AUTONOMOUS)
4 What do you mean by “thread”? What are the advantages that can be obtained by using thread as a 1 3
unit of computation. Write a multithreaded Pthreads program that generates the Fibonacci series.
This program should work as follows.
The user will run the program and will enter on the command line the number of Fibonacci
numbers that the program is to generate. The program will then create a separate thread that will
generate the Fibonacci numbers.
5 Explain Dead lock detection algorithm. Solve the following There 3 3
are 5 resources and 5 processes in a system.
Availability Table
Resources Quantity
A 3
B 2
C 1
D 2
E 1
The quantities of resources requested by the processes are as follows:
Request Table: Process-> 1 2 3 4 5
Res A 2 2 1 0 0
Res B 1 1 1 0 1
Res C 1 1 0 1 0
Res D 1 0 1 1 0
Res E 1 1 2 0 0
Case study
Please read the following pdf: