Nim : 20180801049
UTS Operating System
1. Explain the various 4 types of allocation algorithms, and describe the advantages and
disadvantages and describe the process of the four algorithms !
First Fit
In the first fit approach is to allocate the first free partition or hole
large enough which can accommodate the process. It finishes after finding the
first suitable free partition.
Advantage
Fastest algorithm because it searches as little as possible.
Disadvantage
The remaining unused memory areas left after allocation become waste
if it is too smaller. Thus request for larger memory requirement cannot be
accomplished.
Best Fit
The best fit deals with allocating the smallest free partition which
meets the requirement of the requesting process. This algorithm first searches
the entire list of free partitions and considers the smallest hole that is adequate.
It then tries to find a hole which is close to actual process size needed.
Advantage
Memory utilization is much better than first fit as it searches the
smallest free partition first available.
Disadvantage
It is slower and may even tend to fill up memory with tiny useless
holes.
Worst fit
In worst fit approach is to locate largest available free portion so that
the portion left will be big enough to be useful. It is the reverse of best fit.
Advantage
Reduces the rate of production of small gaps.
Disadvantage
If a process requiring larger memory arrives at a later stage then it
cannot be accommodated as the largest hole is already split and occupied.
Buddy's System
Advantage
Buddy system is faster. When a block of size 2k is freed, a hole of 2k
memory size is searched to check if a merge is possible, whereas in other
algorithms all the hole list must be searched.
Disadvantage
It is often become inefficient in terms of memory utilization. As all
requests must be rounded up to a power of 2, a 35KB process is allocated to
64KB, thus wasting extra 29KB causing internal fragmentation. There may be
holes between the buddies causing external fragmentation.
2. What inconveniences that a user can face while interacting with a computer system,
which is without an operating system?
Operating system is a required component of the computer system.
Without an operating system computer hardware is only an inactive electronic
machine, which is inconvenient to user for execution of programs.
As the computer hardware or machine understands only the machine language.
It is difficult to develop each and every program in machine language in order to
execute it.
Thus without operating system execution of user program or to solve user
problems is extremely difficult.
3. Find out which algorithm among FCFS, SJF and Round Robin with quantum 8, would
give the minimum average time for a given workload.
Answer:
FCFS
o Source Code
// C++ program for implementation of FCFS
// scheduling with different arrival time
#include<iostream>
using namespace std;
// Driver code
int main()
{
// Process id's
int processes[] = {1, 2, 3,4,5};
int n = sizeof processes / sizeof processes[0];
return 0;
}
o Output
SJF Preemptive
o Source Code
// C++ program to implement Shortest Job first with Arrival Time
#include <iostream>
using namespace std;
int mat[10][6];
int main()
{
int num, temp;
cout<<"Before Arrange...\n";
cout<<"Process ID\tArrival Time\tBurst Time\n";
for(int i=0; i<num; i++)
{
cout<<mat[i][0]<<"\t\t"<<mat[i][1]<<"\t\t"<<mat[i][2]<<"\n";
}
arrangeArrival(num, mat);
completionTime(num, mat);
cout<<"Final Result...\n";
cout<<"Process ID\tArrival Time\tBurst Time\tWaiting Time\tTurnaround
Time\n";
for(int i=0; i<num; i++)
{
cout<<mat[i][0]<<"\t\t"<<mat[i][1]<<"\t\t"<<mat[i][2]<<"\t\t"<<mat[i][4]<
<"\t\t"<<mat[i][5]<<"\n";
}
}
o Output
o Source Code
struct Process {
int pid; // Process ID
int bt; // Burst Time
int art; // Arrival Time
};
if (check == false) {
t++;
continue;
}
// Update minimum
minm = rt[shortest];
if (minm == 0)
minm = INT_MAX;
// Increment complete
complete++;
check = false;
if (wt[shortest] < 0)
wt[shortest] = 0;
}
// Increment time
t++;
}
}
// Driver code
int main()
{
Process proc[] = { { 1, 6, 0 }, { 2, 4, 1 },
{ 3, 3, 5 }, { 4, 7, 4}, {5,8,6} };
int n = sizeof(proc) / sizeof(proc[0]);
findavgTime(proc, n);
return 0;
}
o Output
Round Robin
o Source Code
// C++ program for implementation of RR scheduling
#include<iostream>
using namespace std;
// Driver code
int main()
{
// process id's
int processes[] = { 1, 2, 3,4,5};
int n = sizeof processes / sizeof processes[0];
// Time quantum
int quantum = 8;
findavgTime(processes, n, burst_time, quantum);
return 0;
}
o Output
Answer:
o The following Figure shows the overall structure of the linux. The kernel sits
directly on the hardware and enables the interactions wit I/O devices and
memory management
o At the lowests level it containts interrupt handlesrs which are the primary way
for interacting with the device, and low level dispatching mechanism
o The dispatching occurs when an interrupt happen and also when the kernel
completes some operations and it is time to start up a user process again
o Now we devide the various kernel subsystems into the three main components.
The I/O component contains the kernel places and responsible for interacting
with the devices and performing the network and strage I/O operations.
o At the highest level the I/O operations are all intergrated under a virtual file
system and at lowest level, all I/O operations pass through some device driver
o All Linux drivers are classified as either a character device driver or block
device driver, with the main main differcnce that random accesses are allowed
on the block devices and not on the character devices
o Technically network devices are really character devices, but they are handled
somewhat differently, so It is preferable to separate them
o The layer above the network drivers handle a kind of the routing function and
making sure that the right packet goes to the right devices
o Sockets interface which allows the program to create sockets for the particular
network
o On the top of the disk drivers is the I/O scheduler who is responsible for ordering
and issuing disk operations request in a way that tries to converse wate full disk
head movement
o At the very top of the block device column are the file system Linux may have
the multiple file system excising concurrently, block device layer provides an
abstraction lyer used by allfile system
o At the right side of the figure there are two key components of the Linux kernel
these are responsible for the memory and process management tasks
o Memory management tasks include maintaining the virtual to physical memory
mappings, maintaining a cache of the recently accessed pages and implementing
a good page replacement policy
o The key responsibility of the process management component is the creation ad
termination of the process, it also includes the process scheduler and code for the
signal handling
o Finally at the very top is the system call interface in to the kernel. All system
calls come here. Causing a trap which switches the execution from the user
mode in to the kernel Mode.