CS2201_OS_Paper_Set_2_Solution
CS2201_OS_Paper_Set_2_Solution
Enrolment No:
8 CO-1
For each of the following, describe the transitions taken by the process and state whether
it is necessary for the process scheduler to run:
(i) The running process is interrupted by a timer. The timer interrupt service
routine determines that the time slice given to the process has not yet
expired.
(ii) As in (i) but the time slice given to the process has expired.
(iii) A running process makes a system call which can be serviced
immediately by the kernel.
(iv) A running process makes a system call which requires an I/O operation
to be initiated.
Ans:
(i) In this scenario, since the time slice given to the process has not yet expired, the
interrupt service routine will simply return to the running process and allow it to
continue executing.
(ii) In this scenario, the interrupt service routine will save the state of the running process
and schedule a new process to run. The previously running process is put on hold until
it is selected again by the scheduler.
(iii) When a running process makes a system call that can be immediately serviced by
the kernel, the process is put on hold and the kernel executes the system call on behalf
of the process. Once the system call is completed, the kernel returns the control back to
the process.
(iv) When a running process makes a system call that requires an I/O operation to be
initiated, the kernel will put the process on hold and schedule another process to run.
The kernel will then initiate the required I/O operation and when it is completed, the
process will be put back on the ready queue and scheduled to run again by the scheduler.
Q B2
(a) Differentiate file Access methods sequential, direct and indexed sequential
access method (ISAM).
(b) What is a File? List the various File Attributes. CO-6
4+2 =
6
CO-2
(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.
a) How many bits in the logical address specify the page number and offset within
the page?
b) How many bits are in a logical address and what is the size of logical address
space?
c) How many bits in the physical address specify the page frame number and offset
within the frame?
d) How many bits are in a physical address and what is the size of physical address
space?
Q B3
Ans:
a) number of bits needed to specify page number : number of entries in page table=
number of pages in logical address. 64 entries so 64 pages so number of bits= 8
log64= 6bits CO-5
number of bits for offset within the page is nothing but number of bits needed to
address each word within the page = log(512)=9 bits
if you are asking size of logical address space, then number of pages*pagesize= 64*512
bytes= 32KB
Consider the following system snapshot using data structures in the Banker’s algorithm,
Q B4 with resources A, B, C and D, and process P0 to P4: 8 CO-4
Allocation Matrix Max Matrix Available
Matrix
A B C D A B C D A B C D
P0 0 1 1 0 0 2 1 0 1 5 2 0
P1 1 2 3 1 1 6 5 2
P2 1 3 6 5 2 3 6 6
P3 0 6 3 2 0 6 5 2
P4 0 0 1 4 0 6 5 6
ii) Is the system in a safe state? If yes, obtain the safe sequence.
iii) If a request from process P1 arrives for additional resources of (0,2,1,0). Can
the Banker’s algorithm grant the request immediately?
Ans: (i)
Need Matrix
(ii) The system is in a safe state and the processes will be executed in the following
order: P0,P3,P4,P1,P2
(iii) the system is in a safe state when the processes are run in the following order:
I. Find out turnaround time for each process using the non-pre-emptive Priority
Scheduling (a smaller priority number implies a higher priority)?
II. Find out turnaround time for each process using Pre-emptive Priority
Scheduling (a smaller priority number implies a higher priority)?
III. Find out turnaround time for each process using non-pre-emptive Shortest
Job First Time?
IV. Find out turnaround time for each processes using Pre-emptive Shortest Job
Q C1 First Time (or Shortest-Remaining-Time-First)?
10 CO-3
Consider the following page reference string:
1,2,3,4,2,1,5,6,2,1,2,3,7,6,3,2,1,2,3,6
Indicate page faults and calculate total number of page faults for FIFO, LRU and
Optimal page replacement algorithms. Calculate page fault with page frames 4.
Remember initially all the frames are empty.
Ans: LRU Question 5 : 4 Frames, LRU
1 2 3 4 2 1 5 6 2 1
Q C2 1 1 1 1 1 1 1 1 1 1 10 CO-5
2 2 2 2 2 2 2 2 2
3 3 3 3 5 5 5 5
4 4 4 4 6 6 6
F F F F F F
2 3 7 6 3 2 1 2 3 6
1 1 1 6 6 6 6 6 6 6
2 2 2 2 2 2 2 2 2 2
5 3 3 3 3 3 3 3 3 3
6 6 7 7 7 7 1 1 1 1
F F F F
Question 5 : 4 Frames, OPT
OPT
1 2 3 4 2 1 5 6 2 1
1 1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3
4 4 4 5 6 6 6
F F F F F F
2 3 7 6 3 2 1 2 3 6
1 1 7 7 7 7 1 1 1 1
2 2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3 3 3
6 6 6 6 6 6 6 6 6 6
F F
1 2 3 4 2 1 5 6 2 1
1 1 1 1 1 1 5 5 5 5
2 2 2 2 2 2 6 6 6
3 3 3 3 3 3 2 2
4 4 4 4 4 4 1
F F F F F F F F
2 3 7 6 3 2 1 2 3 6
5 3 3 3 3 3 1 1 1 1
6 6 7 7 7 7 7 7 3 3
2 2 2 6 6 6 6 6 6 6
1 1 1 1 1 2 2 2 2 2
F F F F F F
P(&s2);
P(&s1); x = x*2;
V(&s1);
5+5
/* thread B */
P(&s1);
x = x*x;
V(&s1);
/* thread C */
P(&s1);
x = x+3;
V(&s2);
V(&s1);
Ans: The possible sequences are B,C,A (x = 6) or C,A,B (x = 36) or C,B,A (x = 18).
(b) What could the output of the concurrent execution of process A and process B
be? (State all possible outputs).
CO-2
int x=0;
int y=0; “initialization”
Process A Process B
Q D2 A disk has 200 tracks (numbered 0 through 199). At a given time, it was serving the
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.
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.
10 CO-6