0% found this document useful (0 votes)
1 views

OS Tutorial 4 Ques

Uploaded by

f20220233
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

OS Tutorial 4 Ques

Uploaded by

f20220233
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

BPDC, Dubai - First Semester, 2024-2025

Course No: CS F372 Operating Systems Course Title: OS


Date: TUTORIAL

Id No: Name:

1. A counting semaphore is initialized to 1. Twelve wait operations and seven signal


operations are performed on it. What is the number of processes waiting on this semaphore?

struct semaphore { void signal(semaphore s){


int count; s.count++;
queueType queue;} if (s.count <= 0)
{
void wait(semaphore s){ remove a process P from s.queue;
s.count--; place process P on ready list;
if (s.count < 0){ }
place this process in s.queue;
block this process } }

Ans: 4 processes

2. A binary semaphore is initialized to 1. Five wait operations are performed on it in a row,


followed by 8 signal operations. Now 5 more wait operations are performed on it. What is the
number of processes waiting on this semaphore?

struct binary_semaphore void signalB(semaphore s){


{ if (s.queue.is_empty())
enum (zero, one) value; s.value = 1;
queueType queue;}; else{
remove a process P from s.queue;
void waitB(binary_semaphore s){ place process P on ready list; }
if (s.value == 1) }
s.value = 0;
else {
place this process in s.queue;
block this process; } }

Ans: 4 processes

3. Ten processes share a critical section implemented by using a counting semaphore named
x initialized to 1. Nine of these processes use the code wait(x); {critical section} signal(x).
However, one process erroneously uses the code signal(x); {critical section} signal(x). What is
the maximum number of processes that can be in the critical section at the same time?
wait(x);
{critical section}
signal(x)

signal(x);
{critical section}
signal(x)
Ans: 3 processes

4. Consider the Readers/writers problem. Time for read or write operation takes 5 units.
Ignore the time involved in execution of the rest of the instructions for reader and writer.
Assume both the semaphores mutex and rw_mutex are counting semaphores and are
initialized with value =1. The timings of activations of Reader/writer Threads or processes are
as given below:

Reader process: Writer process:

Time Process
T=0 Writer1
T=3 Reader1
T=7 Writer2
T=9 Reader2

Write the transitions of the variables at the given time slots in the tabular format as given
below: If a variable does not undergo any transition at a given time then specify its current
value. When will writer2 complete the write operation?
Ans:
5. The following table shows the code fragments of 3 concurrent processes and 3 binary
semaphores. The semaphores are initialized as S0 = 1, S1 = 0 and S2 = 0. What is the maximum
number of times P0 can print 0?

Process P0 Process P1 Process P2


do Wait(S1) Wait(S2)
{ Signal(S0) Signal(S0)

wait(S0)
print 0
signal(S1)
signal(S2)
} while(1)

Ans: 3 times

You might also like