0% found this document useful (0 votes)
3 views30 pages

OS Lab File - Final

The document outlines the hardware and software requirements for various operating systems including UNIX, Linux, Windows XP, and Windows 7/8, highlighting their specific needs and use cases. It also includes programming examples implementing different CPU scheduling techniques such as First Come, First Serve, Priority Scheduling, Shortest Job First, and Round Robin. Each program demonstrates how to manage process scheduling and calculate average waiting times.

Uploaded by

rishabhverma4509
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views30 pages

OS Lab File - Final

The document outlines the hardware and software requirements for various operating systems including UNIX, Linux, Windows XP, and Windows 7/8, highlighting their specific needs and use cases. It also includes programming examples implementing different CPU scheduling techniques such as First Come, First Serve, Priority Scheduling, Shortest Job First, and Round Robin. Each program demonstrates how to manage process scheduling and calculate average waiting times.

Uploaded by

rishabhverma4509
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Program-01

Study of Hardware and Software Requirements of Different Operating Systems:


[UNIX, Linux, Windows XP, and Windows 7 / Windows 8]

Theory
An Operating System (OS) is system software that manages hardware resources and provides
services to users and applications. Each OS has specific minimum and recommended
requirements for proper functioning.
 Hardware requirements → CPU, RAM, storage, graphics, etc.
 Software requirements → file systems, drivers, libraries, compatibility
Different OSs are designed for different purposes:
 UNIX → enterprise/server
 Linux → open-source, flexible
 Windows → user-friendly desktop OS

System Requirements Comparison


📌 1. UNIX
Hardware Requirements (Typical):
 Processor: Multi-core CPU
 RAM: 512 MB minimum (2 GB+ recommended)
 Storage: 10–20 GB
 Network support required
Software Requirements:
 Shell (Bash, Korn shell)
 File system support (UFS, ZFS)
 Multi-user environment

📌 2. Linux
Hardware Requirements:
 Processor: 1 GHz or higher
 RAM: 512 MB (1–2 GB recommended)
 Storage: 10–25 GB
Software Requirements:
 Kernel + GNU tools
 Package manager (APT, YUM)
 Supports multiple file systems (EXT4, FAT, NTFS)

Highly customizable and runs even on low-end systems

📌 3. Windows XP
Hardware Requirements:
 Processor: 233 MHz
 RAM: 64 MB minimum (128 MB recommended)
 Storage: 1.5 GB
Software Requirements:
 NTFS/FAT file system
 Device drivers
 Basic GUI support
Lightweight but now obsolete and unsupported

📌 4. Windows 7 / Windows 8
Hardware Requirements:
 Processor: 1 GHz
 RAM:
o 1 GB (32-bit)
o 2 GB (64-bit)
 Storage:
o 16 GB (32-bit)
o 20 GB (64-bit)
Software Requirements:
 DirectX 9 graphics
 Advanced drivers
 GUI + multitasking support
👉 More resource-intensive but better performance and UI

📊 Comparison Table
OS Processor RAM Storage Key Feature
UNIX Multi-core 512 MB+ 10–20 GB Multi-user, secure
Linux 1 GHz 512 MB–2 GB 10–25 GB Open-source, flexible
Windows XP 233 MHz 64–128 MB 1.5 GB Lightweight
Windows 7/8 1 GHz 1–2 GB 16–20 GB GUI, multitasking

Observations
 Windows XP requires least resources but is outdated
 Linux is most flexible and efficient
 UNIX is used for high-performance systems
 Windows 7/8 provide better UI but need more resources

The study shows that different operating systems have varying hardware and software requirements
based on their design goals. Lightweight OSs require fewer resources, while modern OSs provide
enhanced features at the cost of higher system requirements.
Program-02
WAP to implement First Come, First Serve Scheduling technique

#include<stdio.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>

struct job
{
int pid,arr,wait,burst;
};

void main()
{
clrscr();
randomize();
int num,i,burst=0;
float avg=0.0;
struct job j[10],temp;
num=rand()%9;
printf("Number of processes are : %d",num);
for(i=0;i<num;i++)
{
j[i].pid=i;
j[i].arr=rand()%11;
j[i].burst=rand()%30;
}
printf("\n\nPID\t\tArrival Time\t\tBurst Time");
for(i=0;i<num;i++)
{
printf("\n\n%d\t\t\t%d\t\t\t%d",j[i].pid,j[i].arr,j[i].burst);
}
for(i=0;i<num-1;i++)
{
for(int k=0;k<num-1-i;k++)
{
if(j[k].arr>j[k+1].arr)
{
[Link]=j[k].arr;
j[k].arr=j[k+1].arr;
j[k+1].arr=[Link];
[Link]=j[k].pid;
j[k].pid=j[k+1].pid;
j[k+1].pid=[Link];
[Link]=j[k].burst;
j[k].burst=j[k+1].burst;
j[k+1].burst=[Link];
}
}
}

j[0].wait=0;
for(i=1;i<num;i++)
{
burst=burst+j[i-1].burst;
j[i].wait=burst-j[i].arr;
avg+=j[i].wait;
}
printf("\n\n\nPID\t\tArrival Time\t\tBurst Time\t\tWaiting Time");
for(i=0;i<num;i++)
{
printf("\n\n%d\t\t\t%d\t\t\t%d\t\t%d",j[i].pid,j[i].arr,j[i].burst,j[i].wait);
}
printf("\n\nExecution is done in the following order :");
for(i=0;i<num;i++)
{
printf("\n\n\t\t----Process %d is executing----",j[i].pid);
delay(j[i].burst*100);
printf("\n\t\t----Execution over----" );
}
printf("\n\nAverage waiting time is : %f ns",avg/num);
getch();
}
OUTPUT
Program-03
WAP to implement Priority Scheduling technique

#include<conio.h>
#include<stdio.h>
#include<dos.h>
#include<stdlib.h>

struct job
{
int pid,arr,burst,wait, pin, pout;
int prior;
};
void main()
{
clrscr();
randomize();
struct job s[10],temp;
int i,num,burst=0;
float avg=0.0;
num=rand()%9;
printf("\nThe number of processes are: %d",num);
for(i=0;i<num;i++)
{
s[i].pid=i;
s[i].arr=rand()%11;
s[i].burst=rand()%30+1;
s[i].prior=rand()%6;
s[i].pin=0;
s[i].pout=1;
}
s[0].arr=0;
printf("\n\nPID\tArrival Time\tBurst Time\tPriority");
for(i=0;i<num;i++)
printf("\n\n%d\t\t%d\t\t%d\t%d",s[i].pid,s[i].arr,s[i].burst,s[i].prior);
int eo;
int min;
int comp;
comp=0;
eo=0;
int j, flag;
while(comp!=num)
{
for(i=0;i<num;i++)
if(s[i].arr<=eo&&s[i].pout!=0)
s[i].pin=1;
flag=0;
i=0;
while(flag==0&&i<num-1)
{
if(s[i].pin==1&&s[i].pout!=0)
{
min=i;
for(j=0;j<num;j++)
{ f(s[j].pin==1&&s[j].pout!=0)
{ if((s[min].prior>s[j].prior))
{ min=j; flag=1; }
else if((s[min].prior==s[j].prior)&&s[min].arr>s[j].arr)
{ min=j; flag=1;}
}
}
}
i++;
}
printf("\nP%d executes from %d to",s[min].pid,eo);
s[min].pout=0;
s[min].wait=eo-s[min].arr;
eo=eo+s[min].burst;
printf(" %d",eo);
comp++;
}

int twt=0;
for(i=0;i<num;i++)
{ twt=twt+s[i].wait;
}
float awt;
awt=twt/num;
printf("\nAverage waiting time : %f",awt);
getch();
}
OUTPUT
Program-04
WAP to implement SJF technique
#include<conio.h>
#include<stdio.h>
#include<dos.h>
#include<stdlib.h>

struct job
{
int pid,arr,burst,wait, pin, pout;
int prior;
};

void main()
{
clrscr();
randomize();
struct job s[10],temp;
int i,num,burst=0;
float avg=0.0;
num=rand()%9;
printf("\nThe number of processes are: %d",num);
for(i=0;i<num;i++)
{
s[i].pid=i;
s[i].arr=rand()%11;
s[i].burst=rand()%30+1;
s[i].prior=rand()%6;
s[i].pin=0;
s[i].pout=1;
}
s[0].arr=0;
printf("\n\nPID\tArrival Time\tBurst Time");
for(i=0;i<num;i++)
printf("\n\n%d\t\t%d\t\t%d",s[i].pid,s[i].arr,s[i].burst);
int eo;
int min;
int comp;
comp=0;
eo=0;
int j, flag;
while(comp!=num)
{
for(i=0;i<num;i++)
if(s[i].arr<=eo&&s[i].pout!=0)
s[i].pin=1;
flag=0;
i=0;
while(flag==0&&i<num-1)
{
if(s[i].pin==1&&s[i].pout!=0)
{
min=i;
for(j=0;j<num;j++)
{
if(s[j].pin==1&&s[j].pout!=0)
{ if((s[min].burst>s[j].burst))
{ min=j; flag=1; }
else if((s[min].burst==s[j].burst)&&s[min].arr>s[j].arr)
{ min=j; flag=1;}
}
}
}
i++;
}
printf("\nP%d executes from %d to",s[min].pid,eo);
s[min].pout=0;
s[min].wait=eo-s[min].arr;
eo=eo+s[min].burst;
printf(" %d",eo);
comp++;
}
int twt=0;
for(i=0;i<num;i++)
{
twt=twt+s[i].wait;
}
float awt;
awt=twt/num;
printf("\nAverage waiting time : %f",awt);
getch();
}
OUTPUT
Program-05
WAP to implement Round Robbin Scheduling technique
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<time.h>
#define BMAX 5 //BMAX:: Maximum Brust time
#define MAX 5 //MAX:: No. of Processes
#define QTime 3 struct proc
{
int proid;
int bursttime;
int arrivaltime;
int wtime;
int etime;

};

void main()
{
randomize();
int i,arr[(BMAX/QTime)*MAX+1],wait,temp1;
float avgwait;
proc list[MAX],temp;
clrscr();

//randomly generating values for processes


for(i=0;i<MAX;i++)
{ list[i].proid=i;
list[i].bursttime=1+random(BMAX);
if(list[0].bursttime<QTime) list[0].bursttime=QTime;
list[i].arrivaltime=rand()%QTime;
list[0].arrivaltime=0;
}

//printing PID table logic//QTime:: Quantum Time

typedef
printf("\nPID\tBurst\tArrival\n\n");
for(i=0;i<MAX;i++)
{
printf("P%d\t%d\t %d\n",i,list[i].bursttime,list[i].arrivaltime);
}

for(i=1;i<MAX;i++){
for(int j=0;j<MAX-i;j++){
if(list[j].bursttime > list[j+1].bursttime)
{

temp=list[j];
list[j]=list[j+1];
list[j+1]=temp;
}
}

int rr=list[MAX-1].bursttime/QTime+1;
//printf("\nJ==%d\n",rr);

//logic for bubble sort


for(i=1;i<MAX;i++){
for(int j=0;j<MAX-i;j++){
if(list[j].arrivaltime > list[j+1].arrivaltime)
{

temp=list[j];
list[j]=list[j+1];
list[j+1]=temp;
}
}
}

//printing PID table logic


printf("\n\n\nPID\tBurst\tArrival\n\n");
for(i=0;i<MAX;i++)
{
printf("P%d\t%d\t",list[i].proid,list[i].bursttime);
printf(" %d\n",list[i].arrivaltime);
}
getch();
//now the processes are in sorted order we need to generate gantt chart for their execution
int timeline=0,k=0;

for(int j=0;j<rr;j++)
{
for(i=0;i<MAX;i++)
{
if(list[i].bursttime>0)
{
list[i].bursttime=list[i].bursttime-QTime;
if(list[i].bursttime>=0)
{

if(j==0)
list[i].wtime=timeline;
else{
//printf("\n1_(i-1)wtime %d timeline %d (n-1)Endtime
%d",list[i].wtime,timeline,list[i].etime);
list[i].wtime=list[i].wtime+timeline-list[i].etime;
}
timeline=timeline+QTime;
arr[k]=timeline;
list[i].etime=timeline;
//printf("\nPro_ID%d\t%d\t%d",list[i].proid,k,arr[k]);
k=k+1;
}
}
if(list[i].bursttime<0)
{
temp1=list[i].bursttime=list[i].bursttime+QTime;
list[i].bursttime=0;

if(j==0)
list[i].wtime=timeline;
else {
//printf("\n2_(i-1)wtime %d timeline %d (n-1)Endtime
%d",list[i].wtime,timeline,list[i].etime);
list[i].wtime=list[i].wtime+timeline-list[i].etime;
}
timeline=timeline+temp1;
arr[k]=timeline;
list[i].etime=timeline;
// printf("\nPro_ID%d\t%d\t%d",list[i].proid,k,arr[k]);
k=k+1;
}
}
}
//printf("\nk==%d\n",k);
printf("\n\n\n\nGantt Chart\n\n0-");
for(i=0;i<k;i++)
printf("%d-",arr[i]);
printf("\b ");
getch();

for(i=1;i<MAX;i++)
{
for(int j=0;j<MAX-i;j++)
{
if(list[j].proid > list[j+1].proid)
{
temp=list[j];
list[j]=list[j+1];
list[j+1]=temp;
}
}
}
printf("\n\n\n\n");
for(i=0;i<MAX;i++)
{
list[i].wtime=list[i].wtime-list[i].arrivaltime;
printf("\nWaiting Time of proecss ID %d = %d",i,list[i].wtime);
}

wait=0;
for(i=0;i<MAX;i++)
{
wait=list[i].wtime+wait;
}
avgwait=wait/(float)MAX;
printf("\n\n\n\nAverage Waiting Time:: %.2f ",avgwait);
getch();
}
OUTPUT
Program-06
WAP to implement First Come, First Serve Disk Scheduling technique
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>

void main()
{
static int curr, n, i, thm,num[10];
clrscr();
randomize();
printf("\nEnter Current Cylinder number (max 199): ");
scanf("%d", &curr);
printf("\nEnter the length of sequence: ");
scanf("%d", &n);
printf("\n");
for(i = 0; i < n; i++)
{
num[i]=rand()/1000;
printf("%d ", num[i]);
}
printf("\n\n\nThe Sequence is: \n\n");
for(i = 0; i < n; i++)
{
printf("%d > ", curr);
thm = thm + abs(num[i] - curr);
curr = num[i];
}
printf("%d", curr);
printf("\n\nTotal Head Movement: %d", thm);
getch();
}
OUTPUT
Program-07
WAP to implement SSTF Disk Scheduling technique
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>

void main()
{
static int curr, n, i, num[10], j, min, pos, thm, flag[10];
clrscr();
randomize();
printf("\nEnter Current Cylinder number (max 199): ");
scanf("%d", &curr);
printf("\nEnter the length of sequence: ");
scanf("%d", &n);
printf("\n");
for(i = 0; i < n; i++)
{
num[i]=rand()/1000;
printf("%d ", num[i]);
}
printf("\n\nThe Sequence: \n\n");
for(i = 0; i < n; i++)
{
printf("%d > ", curr);
min = 999;
for(j = 0; j < n; j++)
{
if(min > abs(curr - num[j]) && flag[j] != 1)
{
min = abs(curr - num[j]);
pos = j;
}
}
flag[pos] = 1;
thm = thm + abs(num[pos] - curr);
curr = num[pos];
}
printf("%d", curr);
printf("\n\nTotal Head Movement: %d", thm);
getch();
}
OUTPUT
Program-08
WAP to implement LOOK Disk Scheduling technique
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
void main()
{ static int curr, n, i, seq[10], j, min, thm;
clrscr();
randomize();
printf("\nEnter Current Cylinder number (max 199): ");
scanf("%d", &curr);
printf("\nEnter the length of sequence: ");
scanf("%d", &n);
printf("\n");
for(i = 0; i < n; i++)
{
seq[i]=rand()/1000;
printf("%d ", seq[i]);
}
for(i = 0; i < n; i++)
for(j = 0; j < n; j++)
if(seq[i] < seq[j])
{
min = seq[i];
seq[i] = seq[j];
seq[j] = min;
}
for(i = 0; i < n; i++)
if(curr <= seq[i])
break;
printf("\n\nThe Sequence: \n\n%d > ", curr);
for(j = i; j < n; j++)
{
thm=thm+(seq[j]-curr);
printf("%d > ", seq[j]);
curr=seq[j];
}
for(j = i-1; j >= 1; j--)
{
thm=thm+(curr-seq[j]);
printf("%d > ", seq[j]);
curr=seq[j];
}
printf("%d", seq[0]);
thm = thm+(curr-seq[0]);//(seq[n-1] - curr) + (seq[n-1] - seq[0]);
printf("\n\nTotal Head Movement: %d", thm);
getch();
}
OUTPUT
Program-09
WAP to implement C-LOOK Disk Scheduling technique
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>

void main()
{
static int curr, n, i, seq[10], j, min, thm;
clrscr();
randomize();
printf("\nEnter Current Cylinder number (max 199): ");
scanf("%d", &curr);
printf("\nEnter the length of sequence: ");
scanf("%d", &n);
printf("\n");
for(i = 0; i < n; i++)
{
seq[i]=rand()/1000;
printf("%d ", seq[i]);
}
for(i = 0; i < n; i++)
for(j = 0; j < n; j++)
if(seq[i] < seq[j])
{
min = seq[i];
seq[i] = seq[j];
seq[j] = min;
}
for(i = 0; i < n; i++)
if(curr <= seq[i])
break;
printf("\n\nThe Sequence: \n\n%d > ", curr);
for(j = i; j < n; j++)
{
thm=thm+(seq[j]-curr);
printf("%d > ", seq[j]);
curr=seq[j];
}
for(j = 0; j < i-1; j++)
{
thm=thm+abs(curr-seq[j]);
printf("%d > ", seq[j]);
curr=seq[j];
}
thm=thm+(seq[i-1]-curr);
printf("%d", seq[i-1]);
//thm = ((seq[n-1] - curr) + (seq[i-1] - seq[0]));
printf("\n\nTotal Head Movement: %d", thm);
getch();
}
OUTPUT
Program-10
WAP to implement C-SCAN Disk Scheduling technique
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>

void main()
{
static int curr, n, i, seq[10], j, min, thm=0;
clrscr();
randomize();
printf("\nEnter Current Cylinder number (max 199): ");
scanf("%d", &curr);
printf("\nEnter the length of sequence: ");
scanf("%d", &n);
printf("\n");
for(i = 0; i < n; i++)
{
seq[i]=rand()/1000;
printf("%d ", seq[i]);
}
for(i = 0; i < n; i++)
for(j = 0; j < n; j++)
if(seq[i] < seq[j])
{
min = seq[i];
seq[i] = seq[j];
seq[j] = min;
}
for(i = 0; i < n; i++)
if(curr <= seq[i])
break;
printf("\n\n\nThe Sequence is: \n\n%d > ", curr);
for(j = i; j < n; j++)
{
thm=thm+(seq[j]-curr);
printf("%d > ", seq[j]);
curr=seq[j];
}
thm=thm+(199-curr)+199;
curr=0;
for(j = 0; j <i-1; j++)
{
thm=thm+(seq[j]-curr);
printf("%d > ", seq[j]);
curr=seq[j];
}
printf("%d", seq[i-1]);
printf("\n\nTotal Head Movement: %d", thm);
getch();
}
OUTPUT
Program-11
WAP to implement Scan Disk Scheduling technique
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>

void main()
{
static int curr, n, i, seq[10], j, min, thm=0;
clrscr();
randomize();
printf("\nEnter Current Cylinder number (max 199): ");
scanf("%d", &curr);
printf("\nEnter the length of sequence: ");
scanf("%d", &n);
printf("\n");
for(i = 0; i < n; i++)
{
seq[i]=rand()/1000;
printf("%d ", seq[i]);
}
for(i = 0; i < n; i++)
for(j = 0; j < n; j++)
if(seq[i] < seq[j])
{
min = seq[i];
seq[i] = seq[j];
seq[j] = min;
}
for(i = 0; i < n; i++)
if(curr <= seq[i])
break;
printf("\n\n\nThe Sequence is: \n\n%d > ", curr);
for(j = i; j < n; j++)
{
thm=thm+(seq[j]-curr);
printf("%d > ", seq[j]);
curr=seq[j];
}
thm=thm+(199-curr);
curr=199;
for(j = i - 1; j > 0; j--)
{
thm=thm+(curr-seq[j]);
printf("%d > ", seq[j]);
curr=seq[j];
}
printf("%d", seq[0]);
printf("\n\nTotal Head Movement: %d", thm);
getch();
}
OUTPUT
Program-12
WAP to implement LRU Page Replacement Policy
#include<conio.h>
#include<stdio.h>

void main()
{
int mm[3];
int pg[20];
int i,j,k,n,pagefault=0,flag;
printf("\nEnter the no of pages");
scanf("%d",&n);
printf("\nEnter page nos");
for(i=0;i<n;i++)
scanf("%d",&pg[i]);
printf("\nEnter the pages in main memory-enter 0 for no page");
for(i=0;i<3;i++)
scanf("%d",&mm[i]);

for(i=0;i<n;i++)
{
flag=0;
for(j=2;j>=0;j--)
{
if(pg[i]==mm[j])
{
k=j;
while(k!=2)
{
mm[k]=mm[k+1];
k++;
}
mm[k]=pg[i];
flag=1;
}
}
if(flag==0)
{
pagefault++;
k=0;
while(k!=2)
{
mm[k]=mm[k+1];
k++;
}
mm[k]=pg[i];

}
printf("\nPage---%d\nFrame",pg[i]);
for(k=2;k>=0;k--)
printf("\n%d",mm[k]);
}
printf("\nPage Faults-----%d",pagefault);

getch();
}
OUTPUT

You might also like