2Name:
Enrolment No:
End Term Examination, April 2024
Faculty of Engineering, School of Computer Science & Engineering
Department of Computer Science & Engineering
B.Tech - CSE
Course Code: CS2201 Course: Operating System Semester: IV
Time: 03 hrs. Max. Marks: 80
Instructions: All questions are compulsory.
Missing data, if any, may be assumed suitably.
Calculator is allowed
SECTION A (Memory Based Questions)
S.No
Marks CO
.
Differentiate multiprogramming, multiprocessing and multitasking.
Ans: In multiprogramming, multiple programs execute at a same time on a single
Q A1 2 CO-1
device. In Multitasking, a single resource is used to process multiple tasks. When more
than one processing unit is used by a single computer then it is called multiprocessing.
What is a race condition? Give an example.
Ans: A race condition occurs when there is an uncoordinated concurrent access to
shared resources (e.g. memory or device registers), which leads to incorrect behaviour
of the program, deadlocks or lost work.
Q A2 An example would be two process updating a counter simultaneously. Say the counter 2 CO-4
has a value of 1. Process A reads the variable but before updating Process B reads and
updates the counter to 2. Process A, having no knowledge of what Process B does,
updates the counter to 2. The correct behaviour of the program would have the counter
being incremented to 3, not 2.
Write the definition of Acquire () and Release () which are used in the Mutex Lock
Ans:
Q A3 2 CO-4
What is a thread-join operation?
Q A4 Ans: A thread-join operation allows a thread to wait for another thread to finish. It 2 CO-2
puts the calling thread to sleep and wakes when the target thread exits.
Q A5 A system contains three programs, and each requires three tape units for its operation. 2 CO-4
What are the minimum number of tape units which the system does not have
deadlocks?
Ans: If 6 resources are there then it may be possible that all three process have 2
resources and waiting for 1 more resource. Therefore, all of them will have to wait
indefinitely. If 7 resources are there, then atleast one must have 3 resources so
deadlock can never occur.
SECTION B
Q B1 Consider a single processor system supporting two running processes, A and B, with 6 CO-3
the following sequential execution patterns:
A: [CPU 8ms; IO 1ms; CPU 8ms; IO 1ms; CPU 8ms]
B: [CPU 2ms; IO 1ms; CPU 2ms; IO 1ms; CPU 2ms]
Assume that IO operations do not interfere with each other and are blocking, and that
scheduling, and context switch times are negligible.
(i) What is the total time required by the individual process to run to
completion?
(ii) Assume the system runs a non-preemptive scheduler where processes
are scheduled in the order A followed by B, and that B takes priority
over A in the event of a tie. Give the combined execution pattern of the
two processes and determine the total elapsed time for the two
processes to run to completion.
Answer:
(Non-preemptive, starting with job A, does 8ms on job A, 2 ms on job B, 8 ms on job
A, 2 ms on job B, 8 ms on job A, 2ms on job B. I/O is performed while the other job
uses the CPU, so is free. Job A finishes after 28 ms, job B after 30 ms.
If you had started with thread B, B would have finished after 22 ms, A after 30.
You could finish B substantially faster by giving it higher priority: 2ms job B, 1ms job
A (while B performs i/o), 2ms job B, 1ms job A, 2ms job B, then job A finishes
without getting the I/O for free. B finishes after 8ms, A after 32ms.
If we preempt after 4ms, if we start with A, we run A for 4ms, B for 2ms, A for 4ms, B
for 2ms, A for 4ms, B for 2ms, then A for 4 ms, 1ms I/O, A for 8ms. Takes 18ms for
B, 31ms for A. You get different numbers if you start with B.
This is all quite unsatisfactory. Without preemption, and with little I/O, the execution
time of each job is basically dependent on the number of I/O operations, because we
switch on I/O operations. However, if we give priority to the job that takes fewer
resources, it can finish much faster - unsatisfactory, because we don't know which job
takes fewer resources.
Preemption after 4ms makes the process using less CPU time finish faster.
Q B2 Consider six memory partitions of size 200 KB, 400 KB, 600 KB, 500 KB, 300 KB
and 250 KB. These partitions need to be allocated to four processes of sizes 357 KB,
210 KB, 468 KB and 491 KB in that order.
CO-5
Perform the allocation of processes using-
1. First Fit Algorithm
2. Best Fit Algorithm
3. Worst Fit Algorithm
Ans: Ans:
First Fit Algorithm:
8
The first fit algorithm assigns the first available partition that is big enough
to a process. Here is how the algorithm will allocate the memory partitions
to the processes:
Process P1 of size 357 KB:
- First available partition of size 600 KB is allocated to P1. Remaining
partitions are 200 KB, 400 KB, 500 KB, 300 KB and 250 KB.
Process P2 of size 210 KB:
- First available partition of size 400 KB is allocated to P2. Remaining
partitions are 200 KB, 200 KB, 500 KB, 300 KB and 250 KB.
Process P3 of size 468 KB:
- First available partition of size 500 KB is allocated to P3. Remaining
partitions are 200 KB, 200 KB, 132 KB, 300 KB and 250 KB.
Process P4 of size 491 KB:
- No partition of size 491 KB or larger is available. P4 cannot be allocated.
Best Fit Algorithm:
The best fit algorithm assigns the smallest available partition that is big
enough to a process. Here is how the algorithm will allocate the memory
partitions to the processes:
Process P1 of size 357 KB:
- Best fit partition of size 600 KB is allocated to P1. Remaining partitions
are 200 KB, 400 KB, 500 KB, 300 KB and 250 KB.
Process P2 of size 210 KB: CO-4
- Best fit partition of size 400 KB is allocated to P2. Remaining partitions
are 200 KB, 200 KB, 500 KB, 300 KB and 250 KB.
Process P3 of size 468 KB:
- Best fit partition of size 500 KB is allocated to P3. Remaining partitions
are 200 KB, 200 KB, 32 KB, 300 KB and 250 KB.
Process P4 of size 491 KB:
- Best fit partition of size 600 KB is allocated to P4. Remaining partitions
are 200 KB, 200 KB, 32 KB and 250 KB.
Worst Fit Algorithm:
The worst fit algorithm assigns the largest available partition to a process.
Here is how the algorithm will allocate the memory partitions to the
processes:
Process P1 of size 357 KB:
- Worst fit partition of size 600 KB is allocated to P1. Remaining partitions
are 200 KB, 400 KB, 500 KB, 300 KB and 250 KB.
Process P2 of size 210 KB:
- Worst fit partition of size 400 KB is allocated to P2. Remaining partitions
are 200 KB, 200 KB, 500 KB, 300 KB and 250 KB.
Process P3 of size 468 KB:
- Worst fit partition of size 500 KB is allocated to P3. Remaining partitions are 200 KB, 200 KB,
100 KB, 300 KB and 250 KB.
Process P4 of size 491 KB:
- Worst fit partition of size 600 KB is allocated to P4. Remaining partitions are 200 KB, 200 KB,
100 KB and 250 KB.
=(2+3+4)-3+1=7
Q B3 Consider the following system snapshot using data structures in the Banker’s
algorithm, with resources A, B, C and D, and process P0 to P4:
Max Allocation Need Available 8
CO-4
A B C D A B C D A B C D A B C D
P 6 0 1 2 4 0 0 1 ? ? ? ? 3 2 1 1
0
P 1 7 5 0 1 1 0 0
1
P 2 3 5 6 1 2 5 4
2
P 1 6 5 3 0 6 3 3
3
P 1 6 5 6 0 2 1 2
4
Using Banker’s algorithm, answer the following:
i) What are the contents of the Need matrix?
ii) Is the system in a safe state? If yes, obtain the safe sequence.
iii) If a request from process P4 arrives for additional resources of (1,2,0,0).
Can the Banker’s algorithm grant the request immediately?
Ans:
Q B4 6+2 CO-6
(a) Differentiate file Access methods sequential, direct and indexed sequential
access method (ISAM).
(b) What is a File? List the various File Attributes.
(b) We all know that we regularly store information on computers. Computers store
this information on physical storage devices like disks. To use & retrieve this stored
information conveniently, the operating system provides a structured mechanism
(more technically, ‘logical view’) to store this information. Within this logical
framework, the operating system organizes information at various levels of
abstraction. ‘File’ is nothing but a logical storage unit of information. A file represents
the smallest unit of allocation on logical secondary storage. We cannot store
information on our computer unless we store it in files as it is the most basic level of
storage.
The part of the operating system dealing with files is called the file system. The file
system manages and organizes the files.
File Attributes
Each file has characteristics like file name, file type, date (on which file was created),
etc. These characteristics are referred to as ‘File Attributes’. The operating system
associates these attributes with files. In different operating systems files may have
different attributes. Some people call attributes metadata also.
Following are some common file attributes:
Name: File name is the name given to the file. A name is usually a string of characters.
Identifier: Identifier is a unique number for a file. It identifies files within the file
system. It is not readable to us, unlike file names.
Type: Type is another attribute of a file which specifies the type of file such as archive
file (.zip), source code file (.c, .java), .docx file, .txt file, etc.
Location: Specifies the location of the file on the device (The directory path). This
attribute is a pointer to a device.
Size: Specifies the current size of the file (in Kb, Mb, Gb, etc.) and possibly the
maximum allowed size of the file.
Protection: Specifies information about Access control (Permissions about Who can
read, edit, write, and execute the file.) It provides security to sensitive and private
information.
Time, date, and user identification: This information tells us about the date and time on
which the file was created, last modified, created and modified by which user, etc.
SECTION-C (Analytical Based Questions)
Consider the following page reference string:
1, 2, 3, 2, 5, 6, 3, 4, 6, 3
Indicate page faults and calculate total number of page faults for FIFO, LRU and
Optimal page replacement algorithms. Calculate page fault with page frames 3.
Remember initially all the frames are empty.
Q C1
10 CO-5
(a) A computer system has a 36-bit virtual address space with a page size of 8K,
and 4 bytes per page table entry.
i) How many pages are in virtual address space?
ii) What is the maximum size of addressable physical memory.
(b) A translation look-aside buffer (TLB) is sometimes used to optimize paging
systems. A memory chip uses (single level) paging and has a memory access
time of 12 nanoseconds and a TLB search time of 2 nanoseconds. What hit
ratio (the probability that an item is in the TLB) must be achieved if we require
an average (paged) memory access time of 12 nanoseconds?
Ans (a) 1. A 36 bit address can address 2^36 bytes in a byte addressable machine.
Since the size of a page 8K bytes (2^13), the number of addressable pages is 2^36 /
>2^13 = 2^23
2. With 4 byte entries in the page table we can reference 2^32 pages. Since each page
Q C2 5+5 CO-5
is 2^13 B long, the maximum addressable physical memory size is 2^32 * 2^13 = 2^45
B (assuming no protection bits are used).
(b) Effective access time= TLB hit( TLB time + Main Memory Time)+TLB miss (TLB
time + 2 * Main Memory Time)
12=TLB hit (12+2) +TLB miss (2+ 2*12)
12= 14*TLB hit +26 (1-TLB hit)
12= 14*TLB hit +26 - 26* TLB hit
12 TLB hit= 14
TLB hit= 14/12
SECTION-D (Case Study/Application based Question)
Q D1 CO-2
a) Predict the output of the following code segments and justify your answer:
i) void main() int a = 0;
{ int main () {
int i; fork ();
for(i=1;i<=4;i++) a++;
fork(); fork ();
printf(“Hello”); a++; 3+4+3
=10
} if (fork () == 0)
Ans: 16 times Hello will be print {
print (“Hello! \n”);
} else {
print(“Goodbye!\n”);
a++;
print(“a is %d\n”, a);
Ans: “ 4 times” The first call to fork()
results in two processes; each of those
two processes then calls fork() which
results in a total of four processes; the
next call to fork() results in eight
processes, but only the child process (of
which there are four) prints “Hello”.
Each process has its own copy of the
variable a, with no sharing across
processes. Each process will increment ‘a’
three times, resulting in an identical value
of ‘a=3’ for all 8 processes.
CO-5
b) A system is having 3 user processes P1, P2 and P3 where P1 requires 2 units of
resource R, P2 requires 3 units of resource R, P3 requires 4 units of resource R. Obtain
the minimum number of units of R that ensures no deadlock.
Ans:
Minimum number of units of R required for no deadlock is :
=(Resource required by p1-1)+ (Resource required by p2-1)+ (Resource required by
p3- 1)+1
= (1+2+3)+1=7 units or
=(Σxi – n) + 1, where xi is the units required and n is the number of process
Q 13 A disk has 200 tracks (numbered 0 through 199). At a given time, it was serving the CO-6
request of reading data from track 120, and at the previous request, service was for
track 90, the pending request (in order of their arrival) are for track numbers.
10
30,70,115,130,110,80,20,25
How many times will the head change its direction for the disk scheduling policy
FCFS and SSTF, SCAN and LOOK? Calculate the seek time. Draw an appropriate
diagram to explain.