Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

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

SET 1 -Roll Numbers: 1602-21-737-066-76,308


QNo Description of the Question BTL CO
1 Consider a system where the virtual memory page size is 2K (2048 bytes), and main memory 2 2
consists of 4 page frames. Now consider a process which requires 8 pages of storage. At
some point during its execution, the page table is as shown below:

Virtual page Valid Physical page


0 No
1 No
2 Yes 1
3 No
4 Yes 3
5 No
6 Yes 0
7 Yes 2

• List the virtual address ranges for each virtual page.


• List the virtual address ranges that will result in a page fault.
• Give the main memory (physical) addresses for each of the following virtual
addresses (all numbers decimal): (i) 8500, (ii) 14000, (iii) 5000, (iv)2100.
2 a) Distinguish between counting and binary semaphores. Show when does the semaphore 1 3
definition requires busy waiting. Suggest a solution to overcome this problem
b) Explain Bakery Algorithm and give the solution using semaphores.
3 A car is manufactured at each stop on a conveyor belt in a car factory. A car is constructed from 3 3
the following parts - chassis, tires, seats, engine (assume this includes everything under the hood
and the steering wheel), the top cover, and painting. Thus there are 6 tasks in manufacturing a car.
However, tires, seats or the engine cannot be added until the chassis is placed on the belt. The car
top cannot be added until tires, seats and the engine are put in. Finally, the car cannot be painted
until the top is put on.
A stop on the conveyor belt in your car company has four technicians assigned to it - Abe, Bob,
Charlie, and Dave. Abe is skilled at adding tires and painting, Bob can only put the chassis on the
belt, Charlie only knows how to attach the seats, and Dave knows how to add the engine as well as
how to add the top.
Write pseudocode for Abe, Bob, Charlie and Dave to be able to work on the car, without violating
the task order outlined above. You can use semaphores, monitors in your solution.
4 “A Context switch between two threads with in the same process involves less work than a context 1 3
switch between two threads in different process”. Explain with a suitable diagram.
VASAVI COLLEGE OF ENGINEERING (AUTONOMOUS)

5 a)Explain Banker’s Algorithm. 3 3

b)There are 5 resources and 3 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
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

The resources allocated by the system are as follows:


Allocation Table:
Process 1 2 3
RES A 1 2 0
RES B 1 0 1
RES C 0 1 0
RES D 1 0 0
RES E 1 1 0
Is the system in a deadlock? If yes, then what are the process(es) that need to be pre-
empted and in what order, to ensure that deadlock is overcome?
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

SET 2-Roll No: 1602-21-737-077 to 92,309


QNo Description of the Question BTL CO
1 Consider a system where the virtual memory page size is 2K (2048 bytes), and main memory 2 2
consists of 4 page frames. Now consider a process which requires 8 pages of storage. At
some point during its execution, the page table is as shown below:

Virtual page Valid Physical page


0 No
1 No
2 Yes 1
3 No
4 Yes 3
5 No
6 Yes 0
7 Yes 2

• List the virtual address ranges for each virtual page.


• List the virtual address ranges that will result in a page fault.
Give the main memory (physical) addresses for each of the following virtual addresses
(all numbers decimal): (i) 3000, (ii) 11000, (iii) 3200, (iv) 2300.
2 Explain Producer Consumer Problem. Discuss the solution using semaphores and monitors. 1 3
3 Consider a producer-consumer situation, where a process P produces an integer using the function 3 3
produceNext() and sends it to process C. Process C receives the integer from P and consumes it in
the function consumeNext(). After consuming this integer, C must let P know, and P must produce
the next integer only after learning that C has consumed the earlier one. Assume that P and C get a
pointer to a shared memory segment of 8 bytes, that can store any two 4-byte integer-sized fields,
as shown below. Both fields in the shared memory structure are zeroed out initially. P and C can
read or write from it, just as they would with any other data object. Briefly describe how you would
solve the producer-consumer problem described above, using only this shared memory as a means
of communication and synchronization between processes P and C. You must not use any other
synchronization or communication primitive. You are provided template code below which gets a
pointer to the shared memory, and produces/consumes integers. You must write the code for
communicating the integer between the processes using the shared memory, with synchronization
logic as required.
struct shmem_structure
VASAVI COLLEGE OF ENGINEERING (AUTONOMOUS)

{ 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

SET 3 - Roll Numbers: 1602-21-737-093-103,311,312


QNo Description of the Question BTL CO
1 Consider a system where the virtual memory page size is 2K (2048 bytes), and main memory 2 2
consists of 4 page frames. Now consider a process which requires 8 pages of storage. At
some point during its execution, the page table is as shown below:

Virtual page Valid Physical page


0 No
1 No
2 Yes 1
3 No
4 Yes 3
5 No
6 Yes 0
7 Yes 2

• List the virtual address ranges for each virtual page.


• List the virtual address ranges that will result in a page fault.
Give the main memory (physical) addresses for each of the following virtual addresses (all
numbers decimal):
(i) 7600, (ii) 12000, (iii) 3200, (iv) 2140.
VASAVI COLLEGE OF ENGINEERING (AUTONOMOUS)

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

SET 4 - Roll Numbers: 1602-21-737-104-114,313,314


QNo Description of the Question BTL CO
1 Consider a system where the virtual memory page size is 2K (2048 bytes), and main memory 2 2
consists of 4 page frames. Now consider a process which requires 8 pages of storage. At some
point during its execution, the page table is as shown below:

Virtual page Valid Physical page


0 No
1 No
2 Yes 1
3 No
4 Yes 3
5 No
6 Yes 0
7 Yes 2

• List the virtual address ranges for each virtual page.


• List the virtual address ranges that will result in a page fault.
Give the main memory (physical) addresses for each of the following virtual addresses (all
numbers decimal):
(i) 7500, (ii) 14400, (iii) 5100, (iv) 2200.
2 Describe Dining Philosophers problem? Discuss the solution to Dining 1 3
philosopher’s problem using monitors
3 Solve the Sleeping-Barber Problem using semaphores 3 3
A barbershop consists of a waiting room with n chairs and a barber room with one
barber chair. If there are no customers to be served, the barber goes to sleep. If a
customer enters the barber shop and all chairs are occupied then the customer
leaves the shop. If the barber is busy but chairs are available, then the customer sits
in one of the free chairs. If the barber is asleep the customer wakes up the barber.
Write pseudo code to co-ordinate the barber and the customers using
synchronization tools.
VASAVI COLLEGE OF ENGINEERING (AUTONOMOUS)

4 a)Discuss various Multithreading Models in detail. 1 3


Consider a multithreaded banking application. The main process receives requests to tranfer money
from one account to the other, and each request is handled by a separate worker thread in the
application. All threads access shared data of all user bank accounts
Bank accounts are represented by a unique integer account number, a balance, and a lock of type
mylock (much like a pthreads mutex) as shown below.
struct account
{
int accountnum; int
balance;
mylock lock;
};
Each thread that receives a transfer request must implement the transfer function shown below, which
transfers money from one account to the other. Add correct locking (by calling the dolock(&lock) and
unlock(&lock) functions on a mylock variable) to the tranfer function below, so that no race conditions
occur when several worker threads concurrently perform transfers. Note that you must use the finegrained
per account lock provided as part of the account object itself, and not a global lock of your own. Also
make sure your solution is deadlock free, when multiple threads access the same pair of accounts
concurrently.
void transfer(struct account *from, struct account *to, int amount)
{ from->balance -= amount; // dont write anything...
to->balance += amount; // ...between these two lines
}

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

SET 5- Roll Numbers: 1602-21-737-115 TO128


QNo Description of the Question BTL CO
1 Consider a system where the virtual memory page size is 2K (2048 bytes), and main memory 2 2
consists of 4 page frames. Now consider a process which requires 8 pages of storage. At
some point during its execution, the page table is as shown below:

Virtual page Valid Physical page


0 No
1 No
2 Yes 1
3 No
4 Yes 3
5 No
6 Yes 0
7 Yes 2

• List the virtual address ranges for each virtual page.


• List the virtual address ranges that will result in a page fault.
Give the main memory (physical) addresses for each of the following virtual addresses (all
numbers decimal): (i) 6500, (ii) 11000, (iii) 4300, (iv) 1900.
2 Explain Readers Writers problem and give the solution using synchronisation tools. 1 3
3 Write Peterson Algorithm for 2-process synchronization to critical section problem and discuss in 3 3
detail.
Two processes, P1 and P2, need to access a critical section of code. Consider the following
synchronization construct used by the processes:

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

The resources allocated by the system are as follows: Allocation Table:


Process 1 2 3 4 5
Res A 1 2 0 1 0
Res B 1 0 1 1 1
Res C 0 1 0 0 0
Res D 1 0 0 0 0
Res E 1 1 0 1 0
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

Case study
Please read the following pdf:

1. Race conditions – understand all five attempts to avoid


race conditions and list downyour findings.
2. Classical Barber shop problem for synchronization: Write
solution for both fair/unfaircase.

You might also like