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

CS2201_OS_Paper_Set_2_Solution

The document is an examination paper for a B.Tech - CSE course on Operating Systems, consisting of multiple sections with questions on memory management, process scheduling, file systems, and resource allocation. It includes both memory-based and concept-based questions, as well as analytical and case study questions related to various operating system principles. The exam is structured to assess students' understanding of key concepts in operating systems, with a total duration of 3 hours and a maximum score of 80 marks.

Uploaded by

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

CS2201_OS_Paper_Set_2_Solution

The document is an examination paper for a B.Tech - CSE course on Operating Systems, consisting of multiple sections with questions on memory management, process scheduling, file systems, and resource allocation. It includes both memory-based and concept-based questions, as well as analytical and case study questions related to various operating system principles. The exam is structured to assess students' understanding of key concepts in operating systems, with a total duration of 3 hours and a maximum score of 80 marks.

Uploaded by

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

Name:

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
How does aging solve the starvation problem in priority based scheduling system?
Q A1 Ans: It works by increasing the priority of a process as time passes and will eventually 2 CO-3
be the highest priority request (after it has waited long enough)
What are the different IPC mechanisms?
Ans: IPC (Interprocess Communication) is a mechanism that requires the use of
resources like a memory that is shared between processes or threads. With IPC, OS
Q A2 allows different processes to communicate with each other. It is simply used for 2 CO-4
exchanging data between multiple threads in one or more programs or processes. In this
mechanism, different processes can communicate with each other with the approval of
the OS.
How do base register and limit register help in protecting against illegal memory access?
Q A3 Ans: Any access to memory is checked against these two registers. The address should 2 CO-5
be greater or equal than the base address and smaller than (Base register + limit register).
What is the use of the ready queue in scheduling.
Ans: The ready queue stores threads that aren't currently running, that are capable of
resuming execution. There may be several ready queues for each priority level,
Q A4 2 CO-3
depending on the scheduling algorithm. The scheduler consults the ready queue to
determine which process/thread to run next. As the name suggests, the ready queue is a
queue, in order to schedule fairly.
How does a context switch work, and why is it essential?
Ans: A context switch is the process of saving the current state of a process or thread
Q A5 2 CO-1
and loading the state of another process or thread to allow multitasking. It is essential to
allow the illusion of concurrent execution.
SECTION B (Concept Based Questions)
Q B1 The diagram below is a simplified state transition diagram for a process in a generic
operating system.

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.

On a paging system with a page table containing 64 entries of 11 bits (including


valid/invalid bit) each, and a page size of 512 bytes,

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

b) size of logical address=<pagenumber,offset>=6+9 =15 bits

if you are asking size of logical address space, then number of pages*pagesize= 64*512
bytes= 32KB

c) number of bits in physical address = <framenum,offset>

number of bits to address a frame= 10 ( as entry size is 10 bits excluding valid/invalid)

number of bits =10+9=19

d) size of physical address= number of frames*size of each frame= 2^10*2^9 =


512KB

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

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 P1 arrives for additional resources of (0,2,1,0). Can
the Banker’s algorithm grant the request immediately?

Ans: (i)

Need Matrix

Need Matrix = Max Matrix


– Allocation Matrix
A B C D
P0 0 1 0 0
P1 0 4 2 1
P2 1 0 0 1
P3 0 0 2 0
P4 0 6 4 2

(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:

P0,P3,P4,P1,P2. We therefore can grant the resource request.


SECTION-C (Analytical Based Questions)
Consider the following set of processes, with the length of the CPU burst given in
milliseconds:

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

Question 5 : 4 Frames, FIFO


FIFO

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

SECTION-D (Case Study/Application based Question)


Q D1 (a) Consider three concurrently executing threads in the same process using two CO-4
semaphores s1 and s2. Assume s1 has been initialized to 1, while s2 has been
initialized to 0. What are the possible values of the global variable x, initialized
to 0, after all three threads have terminated?
/* thread A */

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

while(x==0) {do-nothing}; printf(“b”);


printf(“a”); x=1;
y=1; while(y==0) {do-
nothing};
y=0; printf(“c”);
printf(“d”);
y=1;
Ans: badc, bacd

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

You might also like