Upload
rajsathyams
View
222
Download
0
Embed Size (px)
Citation preview
8/4/2019 SRM University Btech Cse C Record
1/23
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
SRM UNIVERSITYSRM NAGAR, KATTANKULATHUR - 603203.
SUBJECT : OPRATING SYSTEM LAB
SUBJECTCODE : CS0212
SEMESTER : II CLASS: I year CSE
EX. NO NAME OF THE EXPERIMENTS PAGE NO SIGN
1 CPU Scheduling FCFS 1
2 CPU Scheduling SJF 3
3 CPU Scheduling SJF Priority 5
4 CPU Scheduling Round Robin 8
5 Page Replacements FIFO 11
6 Page Replacements LRU 14
7 Page Replacements - Optimal 17
8 Dead Lock - Detection 20
8/4/2019 SRM University Btech Cse C Record
2/23
Ex. No: 1 CPU SCHEDULING - FCFS
Aim:
To write a new programs CPU Scheduling using First Come First Servealgorithm in c program.
Algorithm:
Step 1 : Start the program
Step 2 : Define maximum array value
Step 3 : To give the total number of Jobs value
Step 4 : To give the jobs time one by one up to total number of jobs
Step 5 : To calculate service time
Step 6 : To calculate individual job waiting time
Step 7 : To calculate total waiting timeStep 8 : To calculate average waiting time
Step 9 : To write each job in waiting time
Step 10 : To write continue total service time, separate job waiting time, total
waiting time and average waiting time
Step 11 : End
Program:
#include
void main(){
int i,n,a[20],wt[20],st=0,twt=0;
float awt;
clrscr();
printf("CPU Scheduling - FCFS");
printf("\n--------------------------");
printf("\nEnter the number of JOBS:");
scanf("%d",&n);
for(i=1;i
8/4/2019 SRM University Btech Cse C Record
3/23
printf("\n--------------------------");
printf("\n%d-JOBS Service time\t: %d",n,st);
printf("\nTotal Waiting Time\t: %d",twt);
printf("\nAverage Waiting Time\t: %.2f\n",awt);
getch();
}
OUTPUT:
CPU Scheduling - FCFS
--------------------------
Enter the number of JOBS: 5
Enter the JOB1:12
Enter the JOB2:25
Enter the JOB3:35
Enter the JOB4:48
Enter the JOB5:56
Waiting Time JOB1: 0
Waiting Time JOB2: 12
Waiting Time JOB3: 37
Waiting Time JOB4: 72
Waiting Time JOB5: 120
--------------------------
5-JOBS Service time : 176
Total Waiting Time : 241
Average Waiting Time : 48.00
Result:
Thus the above CPU Scheduling using First Come First Serve algorithm
Program to compile and run the output was successfully completed.
8/4/2019 SRM University Btech Cse C Record
4/23
Ex. No: 2 CPU SCHEDULING - SJF
Aim:To write a new program CPU Scheduling using Sort Job First algorithm in c
program.
Algorithm:
Step 1 : Start the program
Step 2 : Define maximum array value
Step 3 : To give the total number of Jobs value
Step 4 : To give the jobs time one by one up to total number of jobs
Step 5 : To sort the all jobs in ascending order
Step 6 : To write a sorted jobs in ascending order
Step 7 : To calculate service time
Step 8 : To calculate individual job waiting timeStep 9 : To calculate total waiting time
Step 10 : To calculate average waiting time
Step 11 : To write each job in waiting time
Step 12 : To write continue total service time, separate job waiting time, total
waiting time and average waiting time
Step 13 : End
Program:
#include
void main()
{
int i,j,n,temp=0,a[20],b[20],wt[20],st=0,twt=0;
float awt;
clrscr();
printf("CPU Scheduling - SJF");
printf("\n--------------------------");
printf("\nEnter the number of JOBS:");
scanf("%d",&n);
for(i=0;i
8/4/2019 SRM University Btech Cse C Record
5/23
printf("\nSorting...");
for(i=0;i
8/4/2019 SRM University Btech Cse C Record
6/23
Ex. No: 3 CPU SCHEDULING SJF Priority
Aim:To write a new program CPU Scheduling using SJF Priority algorithm in c
program.
Algorithm:Step 1 : Start the program
Step 2 : Define maximum array value
Step 3 : To give the total number of Jobs value
Step 4 : To give the job time and priority one by one up to total no of jobs
Step 5 : To sort the all jobs based on priority in ascending order
Step 6 : To write a sorted priority and jobs in ascending order
Step 7 : To calculate service timeStep 8 : To calculate individual job waiting time
Step 9 : To calculate total waiting time
Step 10 : To calculate average waiting time
Step 11 : To write each job in waiting time
Step 12 : To write continue total service time, separate job waiting time, total
waiting time and average waiting time
Step 13 : End
Program:
#include
void main()
{
int i,j,n,tempp=0,tempj=0,a[20],b[20],wt[20],st=0,twt=0;
float awt;
clrscr();
printf("CPU Scheduling - SJF Priority");
printf("\n----------------------------");
printf("\nEnter the number of JOBS:");
scanf("%d",&n);
for(i=0;i
8/4/2019 SRM University Btech Cse C Record
7/23
b[j]=tempp;
a[j+1]=a[j];
a[j]=tempj;
}
}
printf("\nPriority Sorting...");
for(i=0;i
8/4/2019 SRM University Btech Cse C Record
8/23
OUTPUT:
CPU Scheduling - SJF Priority
----------------------------
Enter the number of JOBS: 5
Enter JOB1: 10
Enter Priority: 5
Enter JOB2: 20
Enter Priority: 1
Enter JOB3: 60
Enter Priority: 3
Enter JOB4: 70
Enter Priority: 4
Enter JOB5: 80
Enter Priority: 6
Priority Sorting...
Priority: 1 Sort: 20
Priority: 3 Sort: 60
Priority: 4 Sort: 70
Priority: 5 Sort: 10
Priority: 6 Sort: 80
Waiting Time JOB0: 0Waiting Time JOB1: 20
Waiting Time JOB2: 80
Waiting Time JOB3: 150
Waiting Time JOB4: 160
----------------------------
5-JOBS Service time : 240
Total Waiting Time : 410
Average Waiting Time : 82.00
Result:
Thus the above CPU Scheduling using SJF Priority algorithm Program to
compile and run the output was successfully completed.
8/4/2019 SRM University Btech Cse C Record
9/23
Ex. No: 4 CPU SCHEDULING Round Robin
Aim:
To write a new program CPU Scheduling using Round Robin algorithm in cprogram.
Algorithm:Step 1 : Start the program
Step 2 : Define maximum array value
Step 3 : To give the total number of Jobs value
Step 4 : To give the job time one by one up to total no of jobs
Step 5 : To give the time slot value
Step 6 : To write waiting time of each job processing based on time slot order
Step 7 : To calculate service time
Step 8 : To calculate individual job waiting timeStep 9 : To calculate total waiting time
Step 10 : To calculate average waiting time
Step 11 : To write each job in waiting time
Step 12 : To write continue total service time, separate job waiting time, total
waiting time and average waiting time
Step 13 : End
Program:
#include
struct job
{
int pt,st,wt;
}j[10];
void main()
{
int i,svt=0,tst=0,n,t,tw=0;
float aw;
clrscr();
printf("CPU Scheduling - Round Robin");
printf("\n---------------------------");
printf("\n Enter No of JOBS:");scanf("%d",&n);
for(i=1;i
8/4/2019 SRM University Btech Cse C Record
10/23
printf("\n Waiting time of each processing:");
printf("\n ---------------------------------\n");
while(svt!=tst)
{
for(i=1;i=t)
{
printf(" Job %d=%d\t",i,svt);
j[i].pt=j[i].pt-t;
j[i].wt=j[i].wt+(svt-j[i].st);
svt=svt+t;
j[i].st=svt;
}
else
{
if(j[i].pt!=0)
{
printf(" Job %d=%d\t",i,svt);
j[i].wt=j[i].wt+(svt-j[i].st);
svt=svt+j[i].pt;
j[i].pt=j[i].pt-j[i].pt;
}}
}
printf("\n");
}
printf("\n Each JOB Waiting Time List:\n");
printf(" --------------------------");
for(i=1;i
8/4/2019 SRM University Btech Cse C Record
11/23
OUTPUT:
CPU Scheduling - Round Robin
---------------------------
Enter No of JOBS: 3
Enter JOB1 processing time: 4
Enter JOB2 processing time: 2
Enter JOB3 processing time: 6
Enter the Time Slot: 2
Waiting time of each processing:
---------------------------------
Job 1=0 Job 2=2 Job 3=4
Job 1=6 Job 3=8
Job 3=10
Each JOB Waiting Time List:
--------------------------
Waiting time of job 1:4
Waiting time of job 2:2Waiting time of job 3:6
----------------------------
Total Service Time : 12
Total Waiting Time : 12
Average Waiting Time : 4.00
Result:
Thus the above CPU Scheduling using Round Robin algorithm Program to
compile and getting the output was successfully completed.
8/4/2019 SRM University Btech Cse C Record
12/23
Ex No: 5 PAGE REPLACEMENTS FIFO
Aim:
To write a new program Page Replacement using First in First Out algorithmprogram in c program.
Algorithm:Step 1 : Start the program
Step 2 : Define maximum array value
Step 3 : To give the Frame stack Size
Step 4 : To give the total no of inputs
Step 5 : To give the inputs one by one up to total no of inputs
Step 5 : If the input is already found in frame stack value then
Step 6 : To write No Need to Add: The given input is already exists...
Step 7 : Else to add input continueStep 8 : If the input is getting time frame stack is full then
Step 9 : To write Fault: Adjusting the Queue... then
Step 10 : To remove first input value from the frame stack then add input
Step 11 : To write Front Input is Dequeued then write Dequeued value
Step 12 : To calculate the number of fault
Step 13 : To write total number of Fault
Step 14 : End
Program:
#include
#include
void main()
{
int front=0,rear=-1,q[20],n,l,i=0,fault=0,a,k;
clrscr();
printf("\nPage Replacement - FIFO");
printf("\n-----------------------");
printf("\nEnter the frame size:");
scanf("%d",&l);
printf("Enter the Number of Inputs:");
scanf("%d",&n);
while(i
8/4/2019 SRM University Btech Cse C Record
13/23
printf("\nNo Need to Add: The given input is
already exists...\n\n");
}
else
{
rear=rear+1;
q[rear]=a;
}
}
else
{
for(k=front;k
8/4/2019 SRM University Btech Cse C Record
14/23
OUTPUT:
Page Replacement - FIFO
-----------------------
Enter the frame size: 3
Enter the Number of Inputs: 8
Enter the Input1: 1
Enter the Input2: 2
Enter the Input3: 3
Enter the Input4: 1
No Need to Add: The given input is already exists...
Enter the Input5: 4
Fault: Adjusting the Queue... Front Input is Dequeued: 1
Enter the Input6: 5
Fault: Adjusting the Queue... Front Input is Dequeued: 2
Enter the Input7: 3
No Need to Add: The given input is already exists...
Enter the Input8: 4
No Need to Add: The given input is already exists...
----------------------------
Total Number of Faults is: 2
Result:
Thus the above Page Replacement using First in First out algorithm Program
to compile and run the output was successfully completed.
8/4/2019 SRM University Btech Cse C Record
15/23
Ex. No: 6 PAGE REPLACEMENTS - LRU
Aim:
To write a new program Page Replacement using Least Recently UsedAlgorithm in c program.
Algorithm:
Step 1 : Start the program
Step 2 : Define maximum array value
Step 3 : To give the total no of inputs
Step 4 : To give the inputs one by one up to total no of inputs
Step 5 : To give the Frame Queue size
Step 6 : If queue is not full add input to queue else
Step 7 : check if the input is already found in frame queue value then skipStep 8 : else check least recently used the value to be replaced then
Step 9 : fault counter to incremented by 1
Step 10 : To write Queue... then
Step 11 : To calculate the number of fault
Step 12 : To write total number of Fault
Step 13 : End
Program:
#include
struct queue
{
int s,qu;
}q[20];
void main()
{
int a[20],l,n,i,j,k,x=0,front=0,rear=-1,y=1,qr,fault=0;
clrscr();
printf("\nPage Replacement - LRU");
printf("\n----------------------");
printf("\nEnter the number of Inputs:");
scanf("%d",&n);
for(i=0;i
8/4/2019 SRM University Btech Cse C Record
16/23
for(j=front;jrear)
{
for(i=front;i
8/4/2019 SRM University Btech Cse C Record
17/23
OUTPUT:
Page Replacement - LRU
----------------------
Enter the number of Inputs: 12
Enter the Input1:2
Enter the Input2:3
Enter the Input3:2
Enter the Input4:1
Enter the Input5:5
Enter the Input6:2
Enter the Input7:4
Enter the Input8:5
Enter the Input9:3
Enter the Input10:2
Enter the Input11:5
Enter the Input12:2
Enter the frame size: 3
Queue: 2 NextInput: 3 MostUsed:
Queue: 2 3 NextInput: 2 MostUsed:
Queue: 2 3 NextInput: 1 MostUsed: 3 2Queue: 2 3 1 NextInput: 5 MostUsed: 2 1
Queue: 2 5 1 NextInput: 2 MostUsed: 1 5
Queue: 2 5 1 NextInput: 4 MostUsed: 5 2
Queue: 2 5 4 NextInput: 5 MostUsed: 2 4
Queue: 2 5 4 NextInput: 3 MostUsed: 4 5
Queue: 3 5 4 NextInput: 2 MostUsed: 5 3
Queue: 3 5 2 NextInput: 5 MostUsed: 3 2
Queue: 3 5 2 NextInput: 2 MostUsed: 2 5
Queue: 3 5 2
---------------------
The No of Faults: 4
Result:
Thus the above Page Replacement using Least Recently Used Algorithm
Program to compile and getting the output was successfully completed.
8/4/2019 SRM University Btech Cse C Record
18/23
Ex. No: 7 PAGE REPLACEMENTS - OPTIMAL
Aim:
To write a new program Page Replacement using Optimal Algorithm.
Algorithm:
Step 1 : Start the program
Step 2 : Define maximum array value
Step 3 : To give the total no of inputs
Step 4 : To give the inputs one by one up to total no of inputs
Step 5 : To give the Frame Queue size
Step 6 : If queue is not full add input to queue else
Step 7 : check if the input is already found in frame queue value then skip
Step 8 : else check last inserted value in the queue to be replaced thenStep 9 : fault counter to incremented by 1
Step 10 : To write Queue... then
Step 11 : To calculate the number of fault
Step 12 : To write total number of Fault
Step 13 : End
Program:
#include
#include
struct queue
{
int qu,s;
}q[20];
void main()
{
int front=0,rear=-1,n,l,a[50],fault=0,i,j,k,qr,y=1,x=0;
clrscr();
printf("\nPaging OPTIMAL");
printf("\n--------------");
printf("\nEnter the no of inputs:");
scanf("%d",&n);for(i=0;i
8/4/2019 SRM University Btech Cse C Record
19/23
{
if(x
8/4/2019 SRM University Btech Cse C Record
20/23
printf("\n-----------------------");
printf("\nThe No of Faults is :%d",fault);
getch();
}
OUTPUT:
Paging OPTIMAL
--------------
Enter the no of inputs: 12
Enter the input 1:2
Enter the input 2:3
Enter the input 3:2
Enter the input 4:1
Enter the input 5:5
Enter the input 6:2
Enter the input 7:4
Enter the input 8:5
Enter the input 9:3
Enter the input 10:2
Enter the input 11:5
Enter the input 12:2
Enter the frame size: 3
Queue: 2 Next consecutive terms: 3 2 1
Queue: 2 3 Next consecutive terms: 2 1 5
Queue: 2 3 Next consecutive terms: 1 5 2
Queue: 2 3 1 Next consecutive terms: 5 2 4
Queue: 2 3 5 Next consecutive terms: 2 4 5
Queue: 2 3 5 Next consecutive terms: 4 5 3
Queue: 4 3 5 Next consecutive terms: 5 3 2
Queue: 4 3 5 Next consecutive terms: 3 2 5
Queue: 4 3 5 Next consecutive terms: 2 5 2
Queue: 4 2 5 Next consecutive terms: 5 2
Queue: 4 2 5 Next consecutive terms: 2Queue: 4 2 5 Next consecutive terms:
-----------------------
The No of Faults is: 3
Result:
Thus the above Page Replacement using Optimal Algorithm Program to
compile and getting the output was successfully completed.
8/4/2019 SRM University Btech Cse C Record
21/23
Ex. No: 8 DEAD LOCK DETECTION
Aim:
To write a new program Dead Lock detection using c program.
Algorithm:
Step 1 : Start the program
Step 2 : Define maximum array value
Step 3 : To set flag=null
Step 4 : To give the total no of process
Step 5 : To give the claim matrix
Step 6 : To give the allocation matrix
Step 7 : To give the resource vector
Step 8 : To give the available vector
Step 9 : Increment the sum value based on allocation matrixStep 10 : If sum=null add m[i] then increment k by 1
Step 11 : If i!=m[l] then set flag=1to check c[i][j]>temp[j] then flag=null
Step 12 : Else flag=1 then m[k]=I then k is incremented by 1
Step 13 : To do temp[j]+=p[i][j] steps then count no of causing process
Step 14 : To write total number of causing process
Step 14 : End
Program:
#include;
#include;
void main()
{
int found,flag,l,p[4][5],tp,c[4][5],i,j,
k=1,m[5],r[5],a[5],temp[5],sum=0;
clrscr();
printf("DEAD LOCK - DETECTION");
printf("\n---------------------");
printf("\nEnter total no of processes : ");
scanf("%d",&tp);
printf("Enter Claim Matrix\n");
for(i=1;i
8/4/2019 SRM University Btech Cse C Record
22/23
}
printf("\nEnter Resource Vector : ");
for(i=1;i
8/4/2019 SRM University Btech Cse C Record
23/23
OUTPUT:
DEAD LOCK - DETECTION
---------------------
Enter total no of processes : 4
Enter Claim Matrix
0 1 0 0 1
0 0 1 0 1
0 0 0 0 1
1 0 1 0 1
Enter Allocation Matrix
1 0 1 1 0
1 1 0 0 0
0 0 0 1 0
0 0 0 0 0
Enter Resource Vector : 2 1 1 2 1
Enter Available Vector : 0 0 0 0 1
----------------------------------
Deadlock Causing Processes are : 1 2
Result:
Thus the above Page Replacement using Dead Lock detection Program to
compile and getting the output was successfully completed.