Skip to main content

Posts

Showing posts with the label simulation program

Write simulation program for demand paging and show the page scheduling and total number of page faults according to LFU page replacement algorithm. Assume the memory of n frames.

Write simulation program for demand paging and show the page scheduling and total number of page faults according to LFU page replacement algorithm. Assume the memory of n frames. Program: #include <stdio.h> #include <stdlib.h> void main(){ setbuf(stdout,NULL); int f, tp ,al[50][50]={-1, -1}, i,j,pg[50],pf,x,queue[50]; printf("\nEnter total number of frames:"); scanf("%d",&f); printf("\nEnter total number of pages:"); scanf("%d",&tp); printf("\nEnter page string:"); for(i=0;i<tp;i++){ scanf("%d",&pg[i]); } pf=0; for(i=0;i<tp;i++){ for(j=0;j<f;j++){ if(al[j][i]==pg[i]){ break; } } if(f==j){ for(j=0;j<f;j++){ if(al[j][i]==-1){ al[j][i]=pg[i]; queue[++x]=pg[i]; pf++; break; } } if(f==j){ for(j=0;j<f;j++){ if(al[j][i]==queue[x]){ al[j][i]=pg[i]; pf++; x--; } } } } else{ queue[++...

Write the simulation program for non-preemptive scheduling algorithm using SJF. The arrival time and first CPU bursts of different jobs should be input to the system. The output should give the Gantt chart and Turnaround time for each process and average time.

Write the simulation program for non-preemptive scheduling algorithm using SJF. The arrival time and first CPU bursts of different jobs should be input to the system. The output should give the Gantt chart and Turnaround time for each process and average time. Program: #include <stdio.h> #include <stdlib.h> void main(){ setbuf(stdout,NULL); int f,max[10][10]={0,0},al[10][10]={0,0},need[10][10]={0,0},av[10]={0},i,j,m,n,cp[10]={0},sf[10]; printf("\nEnter the number of processes:"); scanf("%d",&m); printf("\nEnter the number of resources:"); scanf("%d",&n); printf("\nEnter Max matrix:"); for(i=0;i<n;i++){ for(j=0;j<m;j++){ scanf("%d",&max[i][j]); } } printf("Enter the allocation matrix:"); for(i=0;i<n;i++){ for(j=0;j<m;j++){ scanf("%d",&al[i][j]); } } printf("Enter available matrix:"); for(i=0;i<n;i++){ scanf("%d...

Write a simulation program for disk scheduling using FCFS algorithm. Accept total number of disk blocks, disk request string, direction of head movement and current head position from the user. Display the list of request order in which it is served. Also display the total number of head movements.

Write a simulation program for disk scheduling using FCFS algorithm. Accept total number of disk blocks, disk request string, direction of head movement and current head position from the user. Display the list of request order in which it is served. Also display the total number of head movements. Program: #include <stdio.h> #include <stdlib.h> void main(){ setbuf(stdout,NULL); int ap[50],i,th,n,cp; printf("\nEnter the number of memory blocks:"); scanf("%d",&n); printf("\nEnter the current position:"); scanf("%d",&cp); printf("\nEnter request string:"); for(i=0;i<n;i++){ scanf("%d",&ap[i]); } th=0; for(i=0;i<n;i++){ if(cp>ap[i]){ th+=cp-ap[i]; cp=ap[i]; } else{ th+=ap[i]-cp; cp=ap[i]; } printf(" %d",ap[i]); } printf("\nTotal head movements:%d",th); }

System with m process and n resource types. Accept number of instances for every resource type. For each process accept the allocation and maximum requirement matrices. Write a program to check if given request of process can be granted immediately or not.

System with m process and n resource types. Accept number of instances for every resource type. For each process accept the allocation and maximum requirement matrices. Write a program to check if given request of process can be granted immediately or not. Program: #include <stdio.h> #include <stdlib.h> void main(){ setbuf(stdout,NULL); int m,n,i,j,al[10][10],av[10],rq[10],tr[10],temp; printf("\nEnter the number of processes:"); scanf("%d",&m); printf("\nEnter the number of resources:"); scanf("%d",&n); printf("\nEnter the allocation matrix:"); for(i=0;i<m;i++){ for(j=0;j<n;j++){ scanf("%d",&al[i][j]); } } printf("\nEnter Total resources array:"); for(i=0;i<n;i++){ scanf("%d",&tr[i]); } printf("\nEnter the request array:"); for(i=0;i<n;i++){ scanf("%d",&rq[i]); } for(i=0;i<n;i++){ temp=0; for(j=0;j<m;...

Write the simulation program for preemptive scheduling algorithm using SJF. The arrival time and first CPU bursts of different jobs should be input to the system. The output should give the Gantt chart and waiting time for each process and average times.

Write the simulation program for preemptive scheduling algorithm using SJF. The arrival time and first CPU bursts of different jobs should be input to the system. The output should give the Gantt chart and waiting time for each process and average times. Program: #include <stdio.h> #include <stdlib.h> struct sch{ int wt,at,ft,bt,st; }pr[50],temp[50]; int rq[50],x,n,timer; void addp(){ int i; for(i=0;i<n;i++){ if(pr[i].at==timer){ rq[++x]=i; } } } int selectp(){ int pp,i; if(x<0){ return(-1); }else{ pp=rq[0]; for(i=1;i<=x;i++){ if(temp[pp].bt>temp[i].bt){ pp=i; } } for(i=pp;i<x;i++){ rq[i]=rq[i+1]; } x--; return(pp); } } void main(){ setbuf(stdout,NULL); int i,t,p; float awt; timer=0; x=-1; printf("Enter the Number of processes:"); scanf("%d",&n); for(i=0;i<n;i++){ printf("\nEnter arrival time:"); scanf("%d",&pr[i].at); printf("\nEnter burs...

Write a simulation program for disk scheduling using LOOK algorithm. Accept total number of disk blocks, disk request string, direction of head movement and current head position from the user. Display the list of request in order in which it is served. Also display the total number of head movements.

Write a simulation program for disk scheduling using LOOK algorithm. Accept total number of disk blocks, disk request string, direction of head movement and current head position from the user. Display the list of request in order in which it is served. Also display the total number of head movements. Program: #include <stdio.h> #include <stdlib.h> void main(){ setbuf(stdout,NULL); int rst[50],cp,th,max,min,tt,n,i,temp; char d; printf("Enter how many blocks:"); scanf("%d",&n); printf("\nEnter current positon of head:"); scanf("%d",&cp); printf("\nEnter total number of tracks:"); scanf("%d",&tt); printf("\nEnter the direction:"); scanf(" %c",&d); printf("\nEnter Request string:"); for(i=0;i<n;i++){ scanf("%d",&rst[i]); } max=rst[0]; min=rst[0]; for(i=0;i<n;i++){ if(min>rst[i]){ min=rst[i]; } if(max<rst[i]){ m...

Write the simulation program for Round Robin with time quantum of 2 units. The arrival of time and first CPU bursts of different jobs should be input to the system. The output should give the Gantt chart and waiting time for each process and average waiting time.

Write the simulation program for Round Robin with time quantum of 2 units. The arrival of time and first CPU bursts of different jobs should be input to the system. The output should give the Gantt chart and waiting time for each process and average waiting time. Program: #include <stdio.h> #include <stdlib.h> #include <conio.h> struct ps{ int at,wt,bt,ft,st; }pr[50], temp[50]; int rq[50], time,x,n,t; void add(){ int i; for(i=0;i<n;i++){ if(time==pr[i].at){ rq[x++]=i; } } } int select(){ int pp, i; if(x==0){ return(-1); }else{ pp = rq[0]; for(i=0;i<x;i++){ rq[i]=rq[i+1]; } x--; return(pp); } } int main(void){ setbuf(stdout,NULL); float awt; int i,p; t=0; time=0; x=0; printf("Enter the Number of processes:"); scanf("%d",&n); for(i=0;i<n;i++){ printf("\nEnter Arrival Time:"); scanf("%d",&pr[i].at); printf("\nEnter CPU burst time:"); scanf("%d...

Write a simulation program for scheduling algorithm using FCFS. The arrival time and first CPU burst of different jobs should be input to the system. The output should give the Gantt chart & turnaround time for each process and average turnaround time.

Write a simulation program for scheduling algorithm using FCFS. The arrival time and first CPU burst of different jobs should be input to the system. The output should give the Gantt chart & turnaround time for each process and average turnaround time. Program: #include <stdio.h> #include <stdlib.h> struct sch{ int at,st,bt,tat,ft; }pr[50]; int rq[50],x,n,timer; void addP(){ int i; for(i=0;i<n;i++){ if(pr[i].at==timer){ rq[x++]=i; } } } int selectP(){ int pp,i; if(x<0){ return(-1); }else{ pp=rq[0]; for(i=0;i<n;i++){ rq[i]=rq[i+1]; } x--; return(pp); } } int main(void){ setbuf(stdout,NULL); int i,t,p; float atat; timer = 0; x=-1; printf("Enter the number of processes:"); scanf("%d",&n); for(i=0;i<n;i++){ printf("\nEnter the Arrival time:"); scanf("%d",&pr[i].at); printf("\nEnter the Burst time:"); scanf("%d",&pr[i].bt); } t=0; addP(...

Write a simulation program for disk scheduling using SCAN algorithm. Accept total number of disk blocks, disk request string, direction of head movement and current head position from the user. Display the list of request in order which it is served. Also display the total number of head movements.

Write a simulation program for disk scheduling using SCAN algorithm. Accept total number of disk blocks, disk request string, direction of head movement and current head position from the user. Display the list of request in order which it is served. Also display the total number of head movements. Program: #include<stdio.h> #include<conio.h> #include <string.h> int main2(void){ setbuf(stdout,NULL); int n,i,pr[50],cp,th,max,small,temp; char d; printf("\n Enter number of disk blocks:"); scanf("%d",&n); printf("\n Enter the current position of head:"); scanf("%d",&cp); printf("Enter the String:"); for(i=0;i<n;i++){ scanf("%d",&pr[i]); } printf("\nEnter the direction of head movement:"); scanf(" %c",&d); max=pr[0]; small=pr[0]; for(i=1;i<n;i++){ if(pr[i]>max){ max = pr[i]; } if(pr[i]<small){ small = pr[i]; } } if(d=='l...