Skip to main content

Posts

Showing posts with the label shortest job first

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 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...