FOS Report: Command Line OS For Demonstration of CPU Scheduling Algorithms
FOS Report: Command Line OS For Demonstration of CPU Scheduling Algorithms
MADE BY:
SHANTAM SINHA
NAVYA NIDHI SHARMA
RAHUL BASAK
PINAKIN CHATURVEDI
Background
The need for a scheduling algorithm arises from the requirement for
modern systems to perform multitasking.
If I run one compilation job and you run five, do you get five times as
much CPU?
Types of scheduling
Round-robin scheduling
PREEMPTIVE SJF
FLOW DIAGRAM
After execution the remaining burst time of process >
time slice then added to the tail of ready queue
NEW
First requested
process
Added at the
tail
Running
I/O or event
completion
Waiting
According to
time slice
I/O or event
wait
Release
Exit
Added as per
assigned
priority
Running
I/O or event
completion
Waiting
Release
I/O or event
wait
Exit
This is used for situations in which processes are easily divided into different
groups. Multiple queues are maintained for processes. Each queue can have
its own scheduling algorithms. Priorities are assigned to each queue.
Scheduling
Algorithm
CPU Overhead
Throughput
Turnaround Time
Response Tim
Low
Low
High
Low
High
Medium
Medium
Priority based
scheduling
Medium
Low
High
High
Round-robin
scheduling
High
Medium
Medium
High
About COSMOS
Cosmos (C# Open Source Managed Operating System) is an operating system
development kit which uses Visual Studio as its development environment. Despite
C# in the name, any .NET based language can be used including VB.NET, FORTRAN,
Delphi Prism, IronPython, F# and more. Cosmos itself and the kernel routines are
primarily written in C#, and thus the Cosmos name. Besides that, NOSMOS (.NET
Open Source Managed Operating System) sounds stupid.
Cosmos is not an operating system in the traditional sense, but instead it is an
"Operating System Kit", or as I like to say "Operating System Legos". Cosmos lets you
create operating systems just as Visual Studio and C# normally let you create
applications. Most users can write and boot their own operating system in just a few
minutes, all using Visual Studio. Milestone 5 includes new features such as an
integrated project type in Visual Studio, and an integrated debugger. You can debug
your operating system directly from Visual Studio using breakpoints.
Cosmos is available in two distributions, the developer kit (dev kit), and the user kit.
The dev kit is designed for users who want to work on Cosmos itself. The user kit is
designed for those who are interested in building their own operating system and
doing some Cosmos work. The dev kit might be thought of as the Cosmos SDK. Most
users should start off with the user kit as it is not so overwhelming like the dev kit.
This article focuses on the user kit.
Code
using System;
using System.Collections.Generic;
using System.Text;
using Sys = Cosmos.System;
namespace iON
{
public class Kernel : Sys.Kernel
{
protected override void BeforeRun()
{
Console.WriteLine("Welcome to iON Operating System.\nTo see the list of available
commands, type 'list'.\n\n");
}
CosmosOS.ACPI.Shutdown();
CosmosOS.ACPI.Disable();
Cosmos.Core.Global.CPU.Halt();
break;
}
case "list":
{
Console.WriteLine("schedule - Demonstrate CPU Scheduling algorithms");
Console.WriteLine("about - Info. about the OS");
Console.WriteLine("list - List the available commands");
Console.WriteLine("shutdown - Shut down the OS");
Console.WriteLine("reboot - Reboot the OS");
break;
}
case "about":
{
Console.WriteLine("iON OS v1.0 - A simple OS to demonstrate CPU Scheduling
Algorithms.");
break;
}
case "reboot":
{
CosmosOS.ACPI.Reboot();
break;
}
case "schedule":
{
Int32 n, i, j, total=0, tempvar, pos, tq, count, sq=0, swt=0, stat=0;
float avwt = 0, avtat = 0;
Int32[] bt = new Int32[20];
Int32[] p = new Int32[20];
Console.Write("P[" + i + 1 + "]:");
temp = Console.ReadLine();
bt[i] = Int32.Parse(temp);
p[i]=i+1;
}
//sorting burst time in ascending order using selection sort
for(i=0;i<n;i++)
{
pos=i;
for(j=i+1;j<n;j++)
{
if(bt[j]<bt[pos])
pos=j;
}
tempvar=bt[i];
bt[i]=bt[pos];
bt[pos]=tempvar;
tempvar=p[i];
p[i]=p[pos];
p[pos]=tempvar;
}
wt[0]=0;
total=0;
Console.WriteLine("\nProcess\t
BT
\tWT\tTT");
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
total+=tat[i];
Console.WriteLine("\nP[" + i + 1 + "]" + "\t\t" + bt[i] + "\t\t" + wt[i] +
"\t\t" + tat[i]);
}
avtat=total/n;
Console.WriteLine("\nProcess\t
BT
\tWT\tTT");
total += tat[i];
Console.WriteLine("\nP[" + i + 1 + "]" + "\t\t" + bt[i] + "\t\t" + wt[i] +
"\t\t" + tat[i]);
}
avtat = total / n;
for(i=0,count=0;i<n;i++)
{
tempvar=tq;
if(st[i]==0)
{
count++;
continue;
}
if(st[i]>tq)
st[i]=st[i]-tq;
else
if(st[i]>=0)
{
tempvar=st[i];
st[i]=0;
}
sq=sq+tempvar;
tat[i]=sq;
}
if(n==count)
break;
}
for(i=0;i<n;i++)
{
wt[i]=tat[i]-bt[i];
swt=swt+wt[i];
stat=stat+tat[i];
}
avwt=swt/n;
avtat=stat/n;
Console.WriteLine("Process
BT
WT
TT");
for(i=0;i<n;i++)
Console.WriteLine("P["+ i+1 + "]
" + tat[i]);
Output
About OS
Scheduling Algorithms
FCFS
SJF
Priority Based
Round Robin