13. Describe the structure of operating system.
Operating system can be implemented with the help of various structures. The structure of the OS
depends mainly on how the various common components of the operating system are interconnected
and melded into the kernel. Depending on this we have following structures of the operating system:
1. Simple/Monolithic- The interfaces and levels of functionality are not well separated.
2. Layered - In this structure the OS is broken into number of layers (levels).
3. Micro kernel – It has smaller kernel.
4. Modules - The kernel has only set of core components and other services are added as dynamically
loadable modules
14. Explain FCFS CPU scheduling with an example.
First Come First Serve (FCFS):
First-Come-First-Served algorithm is the simplest scheduling algorithm.
The Process that requests the CPU first is allocated the CPU first.
Processes are dispatched according to their arrival time on the ready queue.
Implementation of the FCFS policy is easily managed with a FIFO queue.
Poor in performance as average waiting time as high.
Average Turnaround time = (24+27+30)/3 = 27 ms
15. Discuss Dining philosophers problem.
Dining Philosopher Problem:
Consider 5 philosophers to spend their lives in thinking and eating.
A philosopher shares common circular table surrounded by 5 chairs each occupies by one philosopher.
In the center of the table there is a bowl of rice and the table is laid with 5 chopsticks arranged adjacent
to plates as shown in below figure.
When a philosopher thinks she does not interact with her colleagues.
From time to time a philosopher gets hungry and tries to pickup two chopsticks that are closest to her.
A philosopher may pickup one chopstick or two chopsticks at a time but she cannot pickup a chopstick
that is already in hand of the neighbor.
When a hungry philosopher has both her chopsticks at the same time, she eats without releasing her
chopsticks.
When she finishes eating, she puts down both of her chopsticks and starts thinking again.
This problem is considered as classical synchronization problem. This problem could be solved by using
semaphore class chopstick in the philosopher processes.
A philosopher grabs the chopsticks by executing the wait operation on that semaphore. She releases the
chopsticks by executing the signal operation on the appropriate semaphore. Hence the solution provides
necessary synchronization and ensures that no two neighboring philosophers are eating at the same time.
The structure of dining philosopher is as follows:
Semaphore chopstick[5];
do
wait ( chopstick [i]);
wait (chopstick [(i+1)%5]);
.............
/* Eat */
.............
signal (chopstick [i]);
signal (chopstick [(i+1)%5]);
.............
/* Think */
.............
} while (True);
16. Explain segmentation with paging
Pure segmentation is not very popular and not being used in many of the operating systems. However,
Segmentation can be combined with Paging to get the best features out of both the techniques.
In Segmented Paging, the main memory is divided into variable size segments which are further divided
into fixed size pages.
1. Pages are smaller than segments.
2. Each Segment has a page table which means every program has multiple page tables.
3. The logical address is represented as Segment Number (base address), Page number and page offset.
Segment Number → It points to the appropriate Segment Number.
Page Number → It Points to the exact page within the segment
Page Offset → Used as an offset within the page frame
Each Page table contains the various information about every page of the segment. The Segment Table
contains the information about every segment. Each segment table entry points to a page table entry and
every page table entry is mapped to one of the page within a segment.
17. Describe sequential file access and direct file access methods of file.
Sequential Access
Most of the operating systems access the file sequentially. In other words, we can say that most of the files
need to be accessed sequentially by the operating system.
In sequential access, the OS read the file word by word. A pointer is maintained which initially points to
the base address of the file. If the user wants to read first word of the file then the pointer provides that
word to the user and increases its value by 1 word. This process continues till the end of the file.
Modern word systems do provide the concept of direct access and indexed access but the most used
method is sequential access due to the fact that most of the files such as text files, audio files, video files,
etc need to be sequentially accessed.
Direct Access
The Direct Access is mostly required in the case of database systems. In most of the cases, we need filtered
information from the database. The sequential access can be P
Suppose every block of the storage stores 4 records and we know that the record we needed is stored in
10th block. In that case, the sequential access will not be implemented because it will traverse all the blocks
in order to access the needed record.
Direct access will give the required result despite of the fact that the operating system has to perform some
complex tasks such as determining the desired block number. However, that is generally implemented in
database applications.
18. Consider the following set of processes with CPU burst time.
Process Burst time
P1 8
P2 4
P3 6
P4 2
P5 5
i. Draw gantt chart
P4 P2 P5 P3 P1
2 6 11 17 25
i. Average turn around time
(2+6+11+17+25)/5=41
i. Average waiting time
(0+2+6+11+17)/5=20.13
19.
a) Benefits of threads
Responsiveness – may allow continued execution if part of process is blocked, especially important
for user interfaces
Resource Sharing – threads share resources of process, easier than shared memory or message
passing
Economy – cheaper than process creation, thread switching lower overhead than context switching
Scalability – process can take advantage of multiprocessor architectures
b) Banker’s algorithm
2. Banker’s Algorithm
For resource categories that contain more than one instance the resource-allocation graph method does
not work, and more complex.
The Banker's Algorithm gets its name because it is a method that bankers could use to assure that when
they lend out resources they will still be able to satisfy all their clients. ( A banker won't loan out a little
money to start building a house unless they are assured that they will later be able to loan out the rest of
the money to finish the house. )
When a process starts up, it must state in advance the maximum allocation of resources it may request,
up to the amount available on the system.
When a request is made, the scheduler determines whether granting the request would leave the system
in a safe state. If not, then the process must wait until the request can be granted safely.
The banker's algorithm relies on several key data structures: ( where n is the number of processes and m
is the number of resource categories. )
Available[ m ] indicates how many resources are currently available of each type.
Max[ n ][ m ] indicates the maximum demand of each process of each resource.
Allocation[ n ][ m ] indicates the number of each resource category allocated to each process.
Need[ n ][ m ] indicates the remaining resources needed of each type for each process.
Need[i ][ j ] = Max[ i ][ j ] - Allocation[ i ][ j ] for all i, j.
Safety Algorithm
1. Let Workand Finish be vectors of length m and n, respectively. Initialize:
Work = Available
Finish [i] = false fori = 0, 1, …, n- 1
2. Find an isuch that both:
(a) Finish [i] = false
(b) NeediWork
If no suchiexists, go to step 4
3. Work = Work + AllocationiFinish[i] = truego to step 2
4. If Finish [i] == truefor all i, then the system is in a safe state
Resource-Request Algorithm for Process Pi
Requesti = request vector for process Pi. If Requesti[j] = kthen process Pi wants k instances of resource
type Rj
1.If RequestiNeedigo to step 2. Otherwise, raise error condition, since process has exceeded its maximum
claim
2.If RequestiAvailable, go to step 3. Otherwise Pi must wait, since resources are not available
3.Pretend to allocate requested resources to Pi by modifying the state as follows:
Available = Available –Requesti;
Allocationi= Allocationi + Requesti;
Needi=Needi – Requesti;
If safe the resources are allocated to Pi
If unsafe Pi must wait, and the old resource-allocation state is restored
20. a) Page replacement algorithm
In an operating system that uses paging for memory management, a page replacement algorithm is
needed to decide which page needs to be replaced when a new page comes in.
Page replacement algorithms
FIFO Algorithm:
This is the simplest page replacement algorithm. When a Page is to be replaced the oldest one is selected.
Optimum algorithm
Replace the page that will not be used for the longest period of time
LRU algorithm
The LRU algorithm replaces the pages that have not been used for longest period of time.
b) Contiguous file allocation
A single continuous set of blocks is allocated to a file at the time of file creation. Thus, this is a pre-
allocation strategy, using variable size portions. The file allocation table needs just a single entry for each
file, showing the starting block and the length of the file. This method is best from the point of view of the
individual sequential file. Multiple blocks can be read in at a time to improve I/O performance for
sequential processing. It is also easy to retrieve a single block. For example, if a file starts at block b, and
the ith block of the file is wanted, its location on secondary storage is simply b+i-1.
Disadvantage –
External fragmentation will occur, making it difficult to find contiguous blocks of space of sufficient
length. Compaction algorithm will be necessary to free up additional space on disk.
Also, with pre-allocation, it is necessary to declare the size of the file at the time of creation.