Uploaded by jaay072

Mid Exam

advertisement
Air University
Final Term Examination Fall 2020
Subject: Operating Systems
Course Code: CS-225
Class: BSGM
Semester: 4th
Total Marks: 35
Date: 21 May, 2021
Time: 9:00AM – 11:00AM
Max Time Allowed: 2 hrs
FM(s) Name: Naila Rehman
Instructions:
1. There are 4 questions in this exam. You must answer all questions.
2. Answers must be handwritten.
3. Write student ID on the answer sheets.
4. Submit handwritten paper in pdf format on the google classroom.
5. Paper solving time and submission time must not exceed 2 hrs.
Question#01
[7 Marks]
a. For the following program, you need to find the output. (Assume no errors in the program). [2]
b. For the following program, you need to find the output. (Assume no errors in the program). [5]
Question#02
[4 Marks]
Examine the following program carefully and answer the given questions. Thread created by
pthread_create() is named as child thread in questions.
a. What is the status (detached or joinable) of the newly created child thread on the execution of
the given program. [2]
b. Does the child thread release resources upon its termination? [1]
c. If answer to part b is yes then explain how, if no then modify the given program in such a way
that child thread can release resources upon its termination. [1]
Question#03
[12 Marks]
Examine the following structures of producer and consumer processes carefully and answer the
given questions.
/* Shared Data */
Data set
Semaphore rw_mutex = 0
Semaphore mutex = 0
int read_count= 0
/* Binary semaphore */
/* Binary semaphore */
/* Keep track of reader processes in critical section*/
/* Writer Process */
/* Reader Process */
do {
do {
wait(rw_mutex);
...
/* writing is performed */
...
signal(rw_mutex);
} while (true);
wait(mutex);
read_count++;
if (read_count == 1)
wait(rw_mutex);
signal(mutex);
...
/* reading is performed */
...
wait(mutex);
read count--;
if (read_count == 0)
signal(rw_mutex);
signal(mutex);
} while (true);
/* Wait Operation */
/* Signal Operation */
wait(S) {
while (S <= 0)
; // busy wait
S--;
}
signal(S) {
S++;
}
a. Which semaphore is used to ensure mutual exclusive access to the shared data in writer
process. [1]
b. Which semaphore is used to ensure mutual exclusive access to the shared data in reader
process. [1]
c. Examine the reader process for given values of semaphores and identify the number of
readers which can read the shared data. [2]
d. Examine the writer process for given values of semaphores and identify the number of writers
which can access the shared data. [2]
e. Update the value of mutex semaphore with 1. Now examine the reader process for mutex = 1
and rw_mutex = 0 and identify the number of readers which can read the shared data. [2]
f. Update the value of rw_mutex semaphore with 1. Now examine the reader process for
mutex = 1 and rw_mutex = 1 and identify the number of readers which can read the shared
data. [2]
g. What is the purpose of if block in reader process. [2]
Question#04
[ 12 Marks]
a. Does the following solution guarantee mutual exclusion. If yes, then prove it. If not, then give a
suitable interleaving which causes mutual exclusion to be violated [4]
while (busy == true); // empty loop body
if (busy == false)
busy = true;
/*Here is code to access shared resource
busy = false;
b. Consider the following program for processes allocation and release and answer the given
questions
i.
Identify the race condition(s). [2]
ii. Assume if there is a mutex lock with the operations acquire_lock() and release_lock().
Identify that where locking will be placed to prevent the race condition (s). [2]
c. We have studied about the Race Condition. Let us suppose that a you and your friend is sharing a
bank account, you are withdrawing an amount and your friend is depositing an amount at the
same time. So will there be any race condition? If yes then how? What will be the solution to it?
Ignore the latter questions if your answer is No. [4]
Download