ESE Sample Solution-BCA403 OS

You might also like

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

Question 1 (a).

❑ Multilevel Queue CPU scheduling algorithm is a preemptive scheduling algorithm.


Solution 1 (a)
❑ False
Question 1 (b).
❑ Each thread has its own stack.
Solution 1 (b)
❑ True
Question 1 (c).
❑ Starvation implies deadlock.
Solution 1 (c)
❑ False
Question 1 (d).
❑ Virtual memory space is always smaller than physical memory space.
Solution 1 (d)
❑ False
Question 1 (e).
❑ When two or more processes attempt to access the same resource a race condition
occurs.
Solution 1 (e)
❑ True
1
5/5/2024
Question 2(a)
❑ Describe the purpose of system calls and write down the name of any FOUR
system calls.
Solution 2(a)
❑ A system calls in computing is the programmatic method by which a
computer programme asks the kernel of the operating system it is running
on for a service.
❑ When a computer programme requests something from the kernel of the
operating system, it performs a system call.
❑ System call uses Application Programming Interfaces (API) to provide
operating system services to user programmes.
❑ The only ways to access the kernel system are through system calls.
❑ The following is a diagram that illustrates what is system call in an
operating system and how the system call is executed:

2
5/5/2024
Question 2(a)
❑ Describe the purpose of system calls and write down the name of any FOUR
system calls.
Solution 2(a)

Types of
Windows Linux
System Calls
CreateProcess
() fork()
Process Control ExitProcess() exit()
WaitForSingle wait()
Object()
CreateFile() open()
File ReadFile() read()
Management WriteFile() write()
CloseHandle() close()

3
5/5/2024
Question 2(b)
❑ Define Preemptive scheduling and non-preemptive scheduling. Also write down
the name of TWO Preemptive scheduling and non-preemptive scheduling
algorithms.
Solution 2(b)
❑ Preemptive Scheduling: The resources (mainly CPU cycles) are allocated
to the process for a limited amount of time and then taken away, and the
process is again placed back in the ready queue if that process still has
CPU burst time remaining. That process stays in the ready queue till it gets
its next chance to execute. Example includes Round Robin (RR), Shortest
Remaining Time First (SRTF), etc.
❑ Non-Preemptive Scheduling: In this scheduling, once the resources
(CPU cycles) are allocated to a process, the process holds the CPU till it
gets terminated. Example includes FCFS, SJF Non-Preemptive, LJF Non-
Preemptive, etc.

4
5/5/2024
Question 2(c)
❑ Discuss the structure of Counting Semaphore.
Solution 2(c)
❑ Counting Semaphore: A counting semaphore is implemented as-
struct semaphore Signal (semaphore s)
{ {
int value; s.value = s.value + 1;
Queue type L; if (s.value <=0 )
} {
Wait (semaphore s) select a process (PCB) from L;
{ wake up();
s.value = s.value - 1; }
if (s.value < 0) }
{ ❑ Wait() Operation is also known
put process (PCB) in L; by other names such as Down
sleep(); operation, P operation
} ❑ Signal() Operation is also known
else by other names such as Up
return; operation, V operation, Release
5
5/5/2024
} operation
Question 2(d)
❑ Describe the all criteria that any synchronization mechanism proposed to handle
the critical section problem.
Solution 2(d)
❑ Any synchronization mechanism proposed to handle the critical section
problem should meet the following criteria
❑ These criteria includes Mutual Exclusion, Progress, Bounded Wait
(i) Mutual Exclusion
❑ The mechanism must ensure-
▪ The processes access the critical section in a mutual exclusive manner.
▪ Only one process is present inside the critical section at any time.
▪ No other process can enter the critical section until the process already
present inside it completes.
(ii) Bounded Wait
❑ The mechanism should ensure-
▪ The wait of a process to enter the critical section is bounded.
▪ A process gets to enter the critical section before its wait gets over.

6
5/5/2024
Question 2(d)
❑ Describe the all criteria that any synchronization mechanism proposed to handle
the critical section problem.
Solution 2(d)
(iii) Progress
❑ The mechanism must ensure-
▪ An entry of a process inside the critical section is not dependent on the
entry of another process inside the critical section.
▪ A process can freely enter inside the critical section if there is no other
process present inside it.
▪ A process enters the critical section only if it wants to enter.
▪ A process is not forced to enter inside the critical section if it does not
want to enter.

7
5/5/2024
Question 2(e)
❑ Describe the following terms with example: (a) Contiguous Memory Allocation
(b) Non-contiguous memory allocation.
Solution 2(e)
Contiguous Memory Allocation
❑ Contiguous memory allocation is a memory allocation technique.
❑ It allows to store the process only in a contiguous fashion.
❑ Thus, entire process has to be stored as a single entity at one place inside
the memory.
❑ There are two popular techniques used for contiguous memory allocation
such as Static Partitioning and Dynamic Partitioning
❑ This allocation also leads to internal fragmentation.
❑ For example, suppose a fixed-sized memory block assigned to a process is
slightly bigger than its demand. In that case, the remaining memory space
in the block is referred to as internal fragmentation.
❑ When a process in a partition finishes, the partition becomes accessible for
another process to run.

8
5/5/2024
Question 2(e)
❑ Describe the following terms with example: (a) Contiguous Memory Allocation
(b) Non-contiguous memory allocation.
Solution 2(e)
Non-Contiguous Memory Allocation
❑ Non-contiguous memory allocation is a memory allocation technique.
❑ It allows to store parts of a single process in a non-contiguous fashion.
❑ Thus, different parts of the same process can be stored at different places
in the main memory.
❑ There are two popular techniques used for non-contiguous memory
allocation such as Paging and Segmentation.
❑ Non-contiguous memory allocation can decrease memory wastage, but it
also raises address translation overheads.
❑ As the process portions are stored in separate locations in memory, the
memory execution is slowed because time is consumed in address
translation.

9
5/5/2024
Question 2(f)
❑ Define segmentation and why it is required.
Solution 2(f)
Segmentation
❑ In segmentation, process is not divided blindly into fixed size pages.
❑ Rather, the process is divided into modules for better visualization.
❑ Segmentation is a variable size partitioning scheme.
❑ In segmentation, secondary memory and main memory are divided into
partitions of unequal size.
❑ The size of partitions depend on the length of modules.
❑ The partitions of secondary memory are called as segments.
❑ Example: Consider a program is divided into 5 segments as-

10
5/5/2024
Question 2(f)
❑ Define segmentation and why it is required.
Solution 2(f)
Why Segmentation is Required
❑ Till now, we were using Paging as our main memory management
technique. Paging is more close to Operating system rather than the User.
❑ It divides all the process into the form of pages regardless of the fact that a
process can have some relative parts of functions which needs to be loaded
in the same page.
❑ Operating system doesn't care about the User's view of the process. It may
divide the same function into different pages and those pages may or may
not be loaded at the same time into the memory. It decreases the efficiency
of the system.
❑ It is better to have segmentation which divides the process into the
segments. Each segment contain same type of functions such as main
function can be included in one segment and the library functions can be
included in the other segment.

11
5/5/2024
Question 2(g)
❑ Describe the merits and demerits of Indexed Allocation.
Solution 2(g)
Merits of Indexed Allocation
❑ This supports direct access to the blocks occupied by the file and therefore
provides fast access to the file blocks.
❑ A bad data block causes the lost of only that block.
De-merits of Indexed Allocation
❑ A bad index block could cause the lost of entire file.
❑ Size of a file depends upon the number of pointers, a index block can hold.
❑ Having an index block for a small file is totally wastage.
❑ More pointer overhead

12
5/5/2024
Question 2(h)
❑ Define the following terms: (i) Rotational Latency (ii) Queuing Delay and (iii)
Data Transfer Rate.
Solution 2(h)
Rotational Latency
❑ The time taken by the desired sector to come under the read / write head is
called as rotational latency.
❑ It depends on the rotation speed of the spindle
❑ Average rotational latency = 1 / 2 * Time taken for full rotation
Queuing Delay
❑ The time spent waiting for the disk to become free is called as queuing
delay.
Data Transfer Rate
❑ Data transfer rate
= Number of heads * Bytes that can be read in one full rotation *
Number of rotations in one second
= Number of heads * Capacity of one track * Number of rotations in
one second
13
5/5/2024
Question 3
Consider 5 Processes (process id P1, P2, P3, P4, and P5 respectively). Their CPU
Burst Time are- 4, 3, 1, 5, 2 time units, Arrival Time are- 0, 1, 2, 3, 4 time units and
Priority is- 2, 3, 4, 5, 5. If the CPU scheduling policy is Priority Preemptive,
calculate the Average Waiting Time and Average Turnaround Time.
(Higher number represents higher priority).
Solution 3
❑ The Information is given below:
Process Id Arrival Burst Priorit
(CT) TAT WT
(PID) Time (AT) Time (BT) y

P1 0 4 2 15 15 – 0 = 15 15 – 4 = 11

P2 1 3 3 12 12 -1 = 11 11 – 3 = 8

P3 2 1 4 3 3-2=1 1–1=0

P4 3 5 5 8 8-3=5 5–5=0
P5 4 2 5 10 10 – 4 = 6 6 – 2 = 414
5/5/2024
Question 3
Consider 5 Processes (process id P1, P2, P3, P4, and P5 respectively). Their CPU
Burst Time are- 4, 3, 1, 5, 2 time units, Arrival Time are- 0, 1, 2, 3, 4 time units and
Priority is- 2, 3, 4, 5, 5. If the CPU scheduling policy is Priority Preemptive,
calculate the Average Waiting Time and Average Turnaround Time.
(Higher number represents higher priority).
Solution 3
❑ The Gantt chart is given below:
❑ Average Turn Around time = (15 + 11 + 1 + 5 + 6) / 5 = 38 / 5 = 7.6 unit
❑ Average waiting time = (11 + 8 + 0 + 0 + 4) / 5 = 23 / 5 = 4.6 unit

15
5/5/2024
Question 3 (OR)
Consider 6 Processes (process id P1, P2, P3, P4, P5 and P6 respectively). Respectively
their CPU Burst Time are- 4, 5, 2, 1, 6 and 3 time units and Arrival Time are- 0, 1, 2,
3, 4, 6 time units. The value of time quantum is 2 time unit. Calculate the Average
Waiting Time and Average Turnaround Time by using Round Robin CPU
Scheduling Algorithm.
Solution 3 (OR)
❑ The Gantt chart is given below:
Process Id Arrival Burst
(CT) TAT WT
(PID) Time (AT) Time (BT)

P1 0 4 8 8-0=8 8-4=4
P2 1 5 18 18-1=17 17-5=12
P3 2 2 6 6-2=4 4-2=2
P4 3 1 9 9-3=6 6-1=5
P5 4 6 21 21-4=17 17-6=11

P6 6 3 19 19-6=13 13-3=10 16
5/5/2024
Question 3 (OR)
Consider 6 Processes (process id P1, P2, P3, P4, P5 and P6 respectively). Respectively
their CPU Burst Time are- 4, 5, 2, 1, 6 and 3 time units and Arrival Time are- 0, 1, 2,
3, 4, 6 time units. The value of time quantum is 2 time unit. Calculate the Average
Waiting Time and Average Turnaround Time by using Round Robin CPU
Scheduling Algorithm.
Solution 3 (OR)
❑ Average Turn Around time = (8 + 17 + 4 + 6 + 17 + 13) / 6 = 65 / 6 =
10.84 unit
❑ Average waiting time = (4 + 12 + 2 + 5 + 11 + 10) / 6 = 44 / 6 = 7.33
unit

17
5/5/2024
Question 4
Discuss Critical Section with the help of a proper example.
Solution 4
❑ Critical section is a section of the program
where a process access the shared resources
during its execution.
❑ The following illustration shows how
inconsistent results may be produced if multiple
processes execute concurrently without any
synchronization.
❑ Consider-
▪ Two processes P1 and P2 are executing
concurrently.
▪ Both the processes share a common variable
named “count” having initial value = 5.
▪ Process P1 tries to increment the value of
count.
▪ Process P2 tries to decrement the value of
count. 18
5/5/2024
Question 4
Discuss Critical Section with the help of a proper example.
Solution 4
❑ In assembly language, the instructions of the processes may be written as-

19
5/5/2024
Solution 4
❑ Now, when these processes execute concurrently without synchronization,
different results may be produced.
Case-01
❑ The execution order of the instructions may be-
P1(1), P1(2), P1(3), P2(1), P2(2), P2(3)
❑ In this case, Final value of count = 5
Case-02
❑ The execution order of the instructions may be-
P2(1), P2(2), P2(3), P1(1), P1(2), P1(3)
❑ In this case, Final value of count = 5
Case-03
❑ The execution order of the instructions may be-
P1(1), P2(1), P2(2), P2(3), P1(2), P1(3)
❑ In this case, Final value of count = 6
Case-04
❑ The execution order of the instructions may be-
P2(1), P1(1), P1(2), P1(3), P2(2), P2(3)
❑ In this case, Final value of count = 4 20
5/5/2024
Solution 4
❑ Now, when these processes execute concurrently without synchronization,
different results may be produced.
Case-05
❑ The execution order of the instructions may be-
P1(1), P1(2), P2(1), P2(2), P1(3), P2(3)
❑ In this case, Final value of count = 4
❑ It is clear from here that inconsistent results may be produced if multiple
processes execute concurrently without any synchronization.

21
5/5/2024
Question 4 (OR)
Consider the following snapshot of a system and answer the following questions using
the Banker’s algorithm- (i) Determine how many resources of type A, B, C, D are
there? (ii) Find out the content of the need matrix need (iii) Is the system in a safe
state? If it is, find the SAFE SEQUENCE.
Allocation Max Available
Proc
ess A B C A B C A B C
P0 1 1 2 5 4 4
P1 2 1 2 4 3 3
P2 3 0 1 9 1 3 3 2 1
P3 0 2 0 8 6 4
P4 1 1 2 2 2 3

Solution 4 (OR)
❑ (i) The total amount of resources = sum of columns of allocation +
Available
❑ Number of Resource of A = (1+2+3+0+1) + 3 = 10
❑ Number of Resource of B = (1+1+0+2+1) + 2 = 07
❑ Number of Resource of A = (2+2+1+0+2) + 1 = 08
22
5/5/2024
Question 4 (OR)
Consider the following snapshot of a system and answer the following questions using
the Banker’s algorithm- (i) Determine how many resources of type A, B, C, D are
there? (ii) Find out the content of the need matrix need (iii) Is the system in a safe
state? If it is, find the SAFE SEQUENCE.
Solution 4 (OR)
❑ (ii) Need = Max – Allocation

Allocation Max Need


Proc
ess A B C A B C A B C

P0 1 1 2 5 4 4 4 3 2
P1 2 1 2 4 3 3 2 2 1
P2 3 0 1 9 1 3 6 1 2
P3 0 2 0 8 6 4 8 4 4
P4 1 1 2 2 2 3 1 1 1

23
5/5/2024
Question 4 (OR)
Consider the following snapshot of a system and answer the following questions using
the Banker’s algorithm- (i) Determine how many resources of type A, B, C, D are
there? (ii) Find out the content of the need matrix need (iii) Is the system in a safe
state? If it is, find the SAFE SEQUENCE.
Solution 4 (OR)
❑ (iii) If needi of processi is lesser than available, add its allocationi to the
availablei and remove that process Pi from the table.
❑ Need [Process P1] is less than Available. Then,
New Available = Old Available + Allocation(P1)
New Available = [3 2 1] + [ 2 1 2] = [5 3 3]

❑ Need [Process P4] is less than Available. Then,


New Available = Old Available + Allocation(P4)
New Available = [5 3 3] + [1 1 2] = [6 4 5]

❑ Need [Process P2] is less than Available. Then,


New Available = Old Available + Allocation(P2)
New Available = [6 4 5] + [3 0 1 ] = [9 4 6]
24
5/5/2024
Question 4 (OR)
Consider the following snapshot of a system and answer the following questions using
the Banker’s algorithm- (i) Determine how many resources of type A, B, C, D are
there? (ii) Find out the content of the need matrix need (iii) Is the system in a safe
state? If it is, find the SAFE SEQUENCE.
Solution 4 (OR)
❑ (iii) If needi of processi is lesser than available, add its allocationi to the
availablei and remove that process Pi from the table.
❑ Need [Process P3] is less than Available. Then,
New Available = Old Available + Allocation(P3)
New Available = [9 4 6] + [ 0 2 0] = [9 6 6]
❑ Need [Process P0] is less than Available. Then,
New Available = Old Available + Allocation(P0)
New Available = [9 6 6] + [1 1 2] = [10 7 8]
❑ Safe sequence: <𝑃1,𝑃4,𝑃2,𝑃3,𝑃0>

25
5/5/2024
Question 5
Define Effective Access Time. A single level paging scheme uses a Translation
Lookaside buffer (TLB). The effective memory access takes 160 ns and a main
memory access takes 100 ns. Determine the TLB access time (in ns) if the TLB hit
ratio is 60% and there is no page fault?
Solution 5
Effective Access Time
❑ This following formula is valid only when there is single level paging and
there are no page faults.
❑ Effective Access Time (EAT)
= Hit Ratio of TLB * (TLB Access Time + Main Memory Access Time)
+
Miss Ratio of TLB * (TLB Access Time + 2* Main Memory Access
Time)

26
5/5/2024
Question 5
Define Effective Access Time. A single level paging scheme uses a Translation
Lookaside buffer (TLB). The effective memory access takes 160 ns and a main
memory access takes 100 ns. Determine the TLB access time (in ns) if the TLB hit
ratio is 60% and there is no page fault?
Solution 5
❑ Effective access time = 160 ns
❑ Main memory access time = 100 ns
❑ TLB Hit ratio = 60% = 0.6
❑ TLB Miss ratio = 1 – TLB Hit ratio = 1 – 0.6 = 0.4
❑ Effective Access Time = 0.6 x { T ns + 100 ns } + 0.1 x { T ns + 2 x 100
ns }
=> 160 ns = 0.9 x 60 ns + 0.1 x 110 ns
=> 160 = T + 140
=> T = 160-140 = 20 ns

27
5/5/2024
Question 5 (OR)
Calculate the (a) Number of Frames and (b) Size of Page Table if the value of
Logical Address Space = 128 KB, Physical Address Space = 512 KB and Page Size
= 16 KB.
Solution 5 (OR)
❑ LAS = 128 KB, PAS = 512 KB, page size = 16 KB = Frame Size
❑ (a) Number of Frames = Size of Main Memory (PAS) / Frame Size
= 512 KB / 16 KB = 32 = 25
❑ Hence, Page entry size = 5 bits
❑ Number of Pages = Size of Process (LAS) / Page Size = 128 KB / 16 KB
= 8 = 23
❑ (b) Page Table Size = Number of Pages x Page Entry Size
= 23 x 5 bits = 40 bits

28
5/5/2024
Question 6
Define C-Look Disk Scheduling Algorithm. Consider a disk with 200 tracks and the
queue has random requests from different processes in the order: 55, 58, 39, 18, 90,
160, 150, 38, 184. Initially arm is at 100. Find the Average Seek length using C-Look
Disk Scheduling Algorithm.
Solution 6
C-Look Disk Scheduling Algorithm
❑ Circular-LOOK Algorithm is an improved version of the LOOK
Algorithm.
❑ Head starts from the first request at one end of the disk and moves towards
the last request at the other end servicing all the requests in between.
❑ After reaching the last request at the other end, head reverses its direction.
❑ It then returns to the first request at the starting end without servicing any
request in between.
❑ The same process repeats.

29
5/5/2024
Question 6
Define C-Look Disk Scheduling Algorithm. Consider a disk with 200 tracks and the
queue has random requests from different processes in the order: 55, 58, 39, 18, 90,
160, 150, 38, 184. Initially arm is at 100. Find the Average Seek length using C-Look
Disk Scheduling Algorithm.
Solution 6
C-Look Disk Scheduling Algorithm
❑ Circular-LOOK Algorithm is an improved version of the LOOK
Algorithm.
❑ Head starts from the first request at one end of the disk and moves towards
the last request at the other end servicing all the requests in between.
❑ After reaching the last request at the other end, head reverses its direction.
❑ It then returns to the first request at the starting end without servicing any
request in between.
❑ Average Seek length = 319

30
5/5/2024
Question 6 (OR)
Write down the FIVE frequently used commands in UNIX with proper syntax.
Solution 6 (OR)

31
5/5/2024
References
❑ Modern Operating Systems By Andrew S. Tanenbaum
❑ Operating System Concepts By Abraham Silberschatz
❑ Operating Systems By William Stallings
❑ Operating Systems by Dietel,D
❑ https://www.gatevidyalay.com/operating-system/
❑ https://www.tutorialspoint.com/operating_system/os_overview.h
tm
❑ https://www.backblaze.com/blog/ssd-upgrade-guide/
❑ https://www.guru99.com/operating-system-tutorial.html

32
5/5/2024

You might also like