├── FCFS Scheduling Algorithm Without Arrival Time.c ├── LICENSE ├── SJF Scheduling Algorithm Without Arrival Time.c ├── FCFS Scheduling Algorithm.c ├── Non-Preemptive Priority Scheduling (Highest Priority First) Without ArrivalTime Algorithm.c ├── Non-Preemptive Priority Scheduling (Smallest Priority First) Without ArrivalTime Algorithm.c ├── SRTF Scheduling Algorithm.c ├── Non-Preemptive Priority Scheduling (Highest Priority First) Algorithm.c ├── Non-Preemptive Priority Scheduling (Smallest Priority First) Algorithm.c ├── Round Robin Scheduling Algorithm.c ├── Highest Response Ratio Next (HRRN) Scheduling Algorithm.c ├── SJF Scheduling Algorithm.c ├── Preemptive Priority Scheduling (Highest Priority First) Algorithm.c ├── Preemptive Priority Scheduling (Smallest Priority First) Algorithm.c ├── Round Robin (Queue Implementation) Scheduling Algorithm.c └── README.md /FCFS Scheduling Algorithm Without Arrival Time.c: -------------------------------------------------------------------------------- 1 | #include 2 | struct proc 3 | { 4 | int no,bt,ct,tat,wt; 5 | }; 6 | struct proc read(int i) 7 | { 8 | struct proc p; 9 | printf("\nProcess No: %d\n",i); 10 | p.no=i; 11 | printf("Enter Burst Time: "); 12 | scanf("%d",&p.bt); 13 | return p; 14 | } 15 | int main() 16 | { 17 | struct proc p[10],tmp; 18 | float avgtat=0,avgwt=0; 19 | int n,ct=0; 20 | printf("<--FCFS Scheduling Algorithm Without Arrival Time (Non-Preemptive)-->\n"); 21 | printf("Enter Number of Processes: "); 22 | scanf("%d",&n); 23 | for(int i=0;i 2 | struct proc 3 | { 4 | int no,bt,ct,tat,wt; 5 | }; 6 | struct proc read(int i) 7 | { 8 | struct proc p; 9 | printf("\nProcess No: %d\n",i); 10 | p.no=i; 11 | printf("Enter Burst Time: "); 12 | scanf("%d",&p.bt); 13 | return p; 14 | } 15 | int main() 16 | { 17 | struct proc p[10],tmp; 18 | float avgtat=0,avgwt=0; 19 | int n,ct=0; 20 | printf("<--SJF Scheduling Algorithm Without Arrival Time (Non-Preemptive)-->\n"); 21 | printf("Enter Number of Processes: "); 22 | scanf("%d",&n); 23 | for(int i=0;ip[j+1].bt) 28 | { 29 | tmp=p[j]; 30 | p[j]=p[j+1]; 31 | p[j+1]=tmp; 32 | } 33 | printf("\nProcessNo\tBT\tCT\tTAT\tWT\tRT\n"); 34 | for(int i=0;i 2 | struct proc 3 | { 4 | int no,at,bt,ct,tat,wt; 5 | }; 6 | struct proc read(int i) 7 | { 8 | struct proc p; 9 | printf("\nProcess No: %d\n",i); 10 | p.no=i; 11 | printf("Enter Arrival Time: "); 12 | scanf("%d",&p.at); 13 | printf("Enter Burst Time: "); 14 | scanf("%d",&p.bt); 15 | return p; 16 | } 17 | int main() 18 | { 19 | struct proc p[10],tmp; 20 | float avgtat=0,avgwt=0; 21 | int n,ct=0; 22 | printf("<--FCFS Scheduling Algorithm (Non-Preemptive)-->\n"); 23 | printf("Enter Number of Processes: "); 24 | scanf("%d",&n); 25 | for(int i=0;ip[j+1].at) 30 | { 31 | tmp=p[j]; 32 | p[j]=p[j+1]; 33 | p[j+1]=tmp; 34 | } 35 | printf("\nProcessNo\tAT\tBT\tCT\tTAT\tWT\tRT\n"); 36 | for(int i=0;i 2 | struct proc 3 | { 4 | int no,bt,ct,wt,tat,pri; 5 | }; 6 | struct proc read(int i) 7 | { 8 | struct proc p; 9 | printf("\nProcess No: %d\n",i); 10 | p.no=i; 11 | printf("Enter Burst Time: "); 12 | scanf("%d",&p.bt); 13 | printf("Enter Priority: "); 14 | scanf("%d",&p.pri); 15 | return p; 16 | } 17 | void main() 18 | { 19 | int n,ct=0; 20 | float avgtat=0,avgwt=0; 21 | struct proc p[10],temp; 22 | printf("<--Highest Priority First Scheduling Algorithm Without Arrival Time (Non-Preemptive)-->\n"); 23 | printf("Enter Number of Processes: "); 24 | scanf("%d",&n); 25 | for(int i=0;i 2 | struct proc 3 | { 4 | int no,bt,ct,wt,tat,pri; 5 | }; 6 | struct proc read(int i) 7 | { 8 | struct proc p; 9 | printf("\nProcess No: %d\n",i); 10 | p.no=i; 11 | printf("Enter Burst Time: "); 12 | scanf("%d",&p.bt); 13 | printf("Enter Priority: "); 14 | scanf("%d",&p.pri); 15 | return p; 16 | } 17 | void main() 18 | { 19 | int n,ct=0; 20 | float avgtat=0,avgwt=0; 21 | struct proc p[10],temp; 22 | printf("<--Smaller Priority First Scheduling Algorithm Without Arrival Time (Non-Preemptive)-->\n"); 23 | printf("Enter Number of Processes: "); 24 | scanf("%d",&n); 25 | for(int i=0;ip[j+1].pri) 30 | { 31 | temp=p[j]; 32 | p[j]=p[j+1]; 33 | p[j+1]=temp; 34 | } 35 | printf("\nProcess\t\tBT\tPri\tCT\tTAT\tWT\n"); 36 | for(int i=0;i 2 | #define MAX 9999 3 | struct proc 4 | { 5 | int no,at,bt,rt,ct,tat,wt; 6 | }; 7 | struct proc read(int i) 8 | { 9 | struct proc p; 10 | printf("\nProcess No: %d\n",i); 11 | p.no=i; 12 | printf("Enter Arrival Time: "); 13 | scanf("%d",&p.at); 14 | printf("Enter Burst Time: "); 15 | scanf("%d",&p.bt); 16 | p.rt=p.bt; 17 | return p; 18 | } 19 | int main() 20 | { 21 | struct proc p[10],temp; 22 | float avgtat=0,avgwt=0; 23 | int n,s,remain=0,time; 24 | printf("<--SRTF Scheduling Algorithm (Preemptive)-->\n"); 25 | printf("Enter Number of Processes: "); 26 | scanf("%d",&n); 27 | for(int i=0;ip[j+1].at) 32 | { 33 | temp=p[j]; 34 | p[j]=p[j+1]; 35 | p[j+1]=temp; 36 | } 37 | printf("\nProcess\t\tAT\tBT\tCT\tTAT\tWT\n"); 38 | p[9].rt=MAX; 39 | for(time=0;remain!=n;time++) 40 | { 41 | s=9; 42 | for(int i=0;i0) 44 | s=i; 45 | p[s].rt--; 46 | if(p[s].rt==0) 47 | { 48 | remain++; 49 | p[s].ct=time+1; 50 | p[s].tat=p[s].ct-p[s].at; 51 | avgtat+=p[s].tat; 52 | p[s].wt=p[s].tat-p[s].bt; 53 | avgwt+=p[s].wt; 54 | printf("P%d\t\t%d\t%d\t%d\t%d\t%d\n",p[s].no,p[s].at,p[s].bt,p[s].ct,p[s].tat,p[s].wt); 55 | } 56 | } 57 | avgtat/=n,avgwt/=n; 58 | printf("\nAverage TurnAroundTime=%f\nAverage WaitingTime=%f",avgtat,avgwt); 59 | } 60 | -------------------------------------------------------------------------------- /Non-Preemptive Priority Scheduling (Highest Priority First) Algorithm.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define MIN -9999; 3 | struct proc 4 | { 5 | int no,at,bt,ct,wt,tat,pri,status; 6 | }; 7 | struct proc read(int i) 8 | { 9 | struct proc p; 10 | printf("\nProcess No: %d\n",i); 11 | p.no=i; 12 | printf("Enter Arrival Time: "); 13 | scanf("%d",&p.at); 14 | printf("Enter Burst Time: "); 15 | scanf("%d",&p.bt); 16 | printf("Enter Priority: "); 17 | scanf("%d",&p.pri); 18 | p.status=0; 19 | return p; 20 | } 21 | 22 | void main() 23 | { 24 | int n,l,ct=0,remaining; 25 | struct proc p[10],temp; 26 | float avgtat=0,avgwt=0; 27 | printf("<--Highest Priority First Scheduling Algorithm (Non-Preemptive)-->\n"); 28 | printf("Enter Number of Processes: "); 29 | scanf("%d",&n); 30 | for(int i=0;ip[j+1].at) 35 | { 36 | temp=p[j]; 37 | p[j]=p[j+1]; 38 | p[j+1]=temp; 39 | } 40 | p[9].pri=MIN; 41 | remaining=n; 42 | printf("\nProcessNo\tAT\tBT\tPri\tCT\tTAT\tWT\tRT\n"); 43 | for(ct=p[0].at;remaining!=0;) 44 | { 45 | l=9; 46 | for(int i=0;ip[l].pri) 48 | l=i; 49 | p[l].ct=ct=ct+p[l].bt; 50 | p[l].tat=p[l].ct-p[l].at; 51 | avgtat+=p[l].tat; 52 | p[l].wt=p[l].tat-p[l].bt; 53 | avgwt+=p[l].wt; 54 | p[l].status=1; 55 | remaining--; 56 | printf("P%d\t\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n",p[l].no,p[l].at,p[l].bt,p[l].pri,p[l].ct,p[l].tat,p[l].wt,p[l].wt); 57 | } 58 | avgtat/=n,avgwt/=n; 59 | printf("\nAverage TurnAroundTime=%f\nAverage WaitingTime=%f",avgtat,avgwt); 60 | } -------------------------------------------------------------------------------- /Non-Preemptive Priority Scheduling (Smallest Priority First) Algorithm.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define MAX 9999; 3 | struct proc 4 | { 5 | int no,at,bt,ct,wt,tat,pri,status; 6 | }; 7 | struct proc read(int i) 8 | { 9 | struct proc p; 10 | printf("\nProcess No: %d\n",i); 11 | p.no=i; 12 | printf("Enter Arrival Time: "); 13 | scanf("%d",&p.at); 14 | printf("Enter Burst Time: "); 15 | scanf("%d",&p.bt); 16 | printf("Enter Priority: "); 17 | scanf("%d",&p.pri); 18 | p.status=0; 19 | return p; 20 | } 21 | 22 | void main() 23 | { 24 | int n,s,ct=0,remaining; 25 | struct proc p[10],temp; 26 | float avgtat=0,avgwt=0; 27 | printf("<--Smallest Priority First Scheduling Algorithm (Non-Preemptive)-->\n"); 28 | printf("Enter Number of Processes: "); 29 | scanf("%d",&n); 30 | for(int i=0;ip[j+1].at) 35 | { 36 | temp=p[j]; 37 | p[j]=p[j+1]; 38 | p[j+1]=temp; 39 | } 40 | p[9].pri=MAX; 41 | remaining=n; 42 | printf("\nProcessNo\tAT\tBT\tPri\tCT\tTAT\tWT\tRT\n"); 43 | for(ct=p[0].at;remaining!=0;) 44 | { 45 | s=9; 46 | for(int i=0;i 2 | struct proc 3 | { 4 | int no,at,bt,ct,tat,wt,rt; 5 | }; 6 | struct proc read(int i) 7 | { 8 | struct proc p; 9 | printf("\nProcess No: %d\n",i); 10 | p.no=i; 11 | printf("Enter Arrival Time: "); 12 | scanf("%d",&p.at); 13 | printf("Enter Burst Time: "); 14 | scanf("%d",&p.bt); 15 | p.rt=p.bt; 16 | return p; 17 | } 18 | int main() 19 | { 20 | struct proc p[10],tmp; 21 | float avgtat=0,avgwt=0; 22 | int n,tq,ct=0,flag=0,remaining; 23 | printf("<--Round Robin Scheduling Algorithm-->\n"); 24 | printf("Enter Number of Processes: "); 25 | scanf("%d",&n); 26 | printf("Enter Time Quantum: "); 27 | scanf("%d",&tq); 28 | for(int i=0;ip[j+1].at) 33 | { 34 | tmp=p[j]; 35 | p[j]=p[j+1]; 36 | p[j+1]=tmp; 37 | } 38 | remaining=n; 39 | printf("\nProcessNo\tAT\tBT\tCT\tTAT\tWT\n"); 40 | for(int i=0;remaining!=0;) 41 | { 42 | if(p[i].rt<=tq&&p[i].rt>0) 43 | { 44 | ct+=p[i].rt; 45 | p[i].rt=0; 46 | flag=1; 47 | } 48 | else if(p[i].rt>0) 49 | { 50 | p[i].rt-=tq; 51 | ct+=tq; 52 | } 53 | if(p[i].rt==0&&flag==1) 54 | { 55 | flag = 0; 56 | remaining--; 57 | p[i].ct=ct; 58 | p[i].tat=p[i].ct-p[i].at; 59 | avgtat+=p[i].tat; 60 | p[i].wt=p[i].tat-p[i].bt; 61 | avgwt+=p[i].wt; 62 | printf("P%d\t\t%d\t%d\t%d\t%d\t%d\n",p[i].no,p[i].at,p[i].bt,p[i].ct,p[i].tat,p[i].wt); 63 | } 64 | if(i!=n-1&&p[i+1].at<=ct) 65 | i++; 66 | else 67 | i=0; 68 | } 69 | avgtat/=n,avgwt/=n; 70 | printf("\nAverage TurnAroundTime=%f\nAverage WaitingTime=%f",avgtat,avgwt); 71 | } -------------------------------------------------------------------------------- /Highest Response Ratio Next (HRRN) Scheduling Algorithm.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define MIN -9999 3 | struct proc 4 | { 5 | int no,at,bt,ct,tat,wt,completed; 6 | }; 7 | struct proc read(int i) 8 | { 9 | struct proc p; 10 | printf("\nProcess No: %d\n",i); 11 | p.no=i; 12 | printf("Enter Arrival Time: "); 13 | scanf("%d",&p.at); 14 | printf("Enter Burst Time: "); 15 | scanf("%d",&p.bt); 16 | p.completed=0; 17 | return p; 18 | } 19 | void main() 20 | { 21 | int n,l,t,remaining; 22 | float hrr,temp,avgtat=0,avgwt=0; 23 | struct proc p[10],tmp; 24 | printf("<--Highest Response Ratio Next Scheduling Algorithm (Non-Preemptive)-->\n"); 25 | printf("Enter Number of Processes: "); 26 | scanf("%d",&n); 27 | for(int i=0;ip[j+1].at) 32 | { 33 | tmp=p[j]; 34 | p[j]=p[j+1]; 35 | p[j+1]=tmp; 36 | } 37 | remaining=n; 38 | printf("\n\nProcess\t\tAT\tBT\tCT\tTAT\tWT\n"); 39 | for (t=p[0].at;remaining!=0;) 40 | { 41 | hrr=MIN; 42 | for (int i=0;i 2 | struct proc 3 | { 4 | int no,at,bt,it,ct,tat,wt; 5 | }; 6 | struct proc read(int i) 7 | { 8 | struct proc p; 9 | printf("\nProcess No: %d\n",i); 10 | p.no=i; 11 | printf("Enter Arrival Time: "); 12 | scanf("%d",&p.at); 13 | printf("Enter Burst Time: "); 14 | scanf("%d",&p.bt); 15 | return p; 16 | } 17 | int main() 18 | { 19 | int n,j,min=0; 20 | float avgtat=0,avgwt=0; 21 | struct proc p[10],temp; 22 | printf("<--SJF Scheduling Algorithm (Non-Preemptive)-->\n"); 23 | printf("Enter Number of Processes: "); 24 | scanf("%d",&n); 25 | for(int i=0;ip[j+1].at) 30 | { 31 | temp=p[j]; 32 | p[j]=p[j+1]; 33 | p[j+1]=temp; 34 | } 35 | for(j=1;j 2 | #define MIN -9999; 3 | struct proc 4 | { 5 | int no,at,bt,rt,ct,wt,tat,pri,temp; 6 | }; 7 | struct proc read(int i) 8 | { 9 | struct proc p; 10 | printf("\nProcess No: %d\n",i); 11 | p.no=i; 12 | printf("Enter Arrival Time: "); 13 | scanf("%d",&p.at); 14 | printf("Enter Burst Time: "); 15 | scanf("%d",&p.bt); 16 | p.rt=p.bt; 17 | printf("Enter Priority: "); 18 | scanf("%d",&p.pri); 19 | p.temp=p.pri; 20 | return p; 21 | } 22 | void main() 23 | { 24 | int i,n,c,remaining,max_val,max_index; 25 | struct proc p[10],temp; 26 | float avgtat=0,avgwt=0; 27 | printf("<--Highest Priority First Scheduling Algorithm (Preemptive)-->\n"); 28 | printf("Enter Number of Processes: "); 29 | scanf("%d",&n); 30 | for(int i=0;ip[j+1].at) 36 | { 37 | temp=p[j]; 38 | p[j]=p[j+1]; 39 | p[j+1]=temp; 40 | } 41 | max_val=p[0].temp,max_index=0; 42 | for(int j=0;jmax_val) 44 | max_val=p[j].temp,max_index=j; 45 | i=max_index; 46 | c=p[i].ct=p[i].at+1; 47 | p[i].rt--; 48 | if(p[i].rt==0) 49 | { 50 | p[i].temp=MIN; 51 | remaining--; 52 | } 53 | while(remaining>0) 54 | { 55 | max_val=p[0].temp,max_index=0; 56 | for(int j=0;jmax_val) 58 | max_val=p[j].temp,max_index=j; 59 | i=max_index; 60 | p[i].ct=c=c+1; 61 | p[i].rt--; 62 | if(p[i].rt==0) 63 | { 64 | p[i].temp=MIN; 65 | remaining--; 66 | } 67 | } 68 | printf("\nProcessNo\tAT\tBT\tPri\tCT\tTAT\tWT\n"); 69 | for(int i=0;i 2 | #define MAX 9999; 3 | struct proc 4 | { 5 | int no,at,bt,rt,ct,wt,tat,pri,temp; 6 | }; 7 | struct proc read(int i) 8 | { 9 | struct proc p; 10 | printf("\nProcess No: %d\n",i); 11 | p.no=i; 12 | printf("Enter Arrival Time: "); 13 | scanf("%d",&p.at); 14 | printf("Enter Burst Time: "); 15 | scanf("%d",&p.bt); 16 | p.rt=p.bt; 17 | printf("Enter Priority: "); 18 | scanf("%d",&p.pri); 19 | p.temp=p.pri; 20 | return p; 21 | } 22 | void main() 23 | { 24 | int i,n,c,remaining,min_val,min_index; 25 | struct proc p[10],temp; 26 | float avgtat=0,avgwt=0; 27 | printf("<--Smallest Priority First Scheduling Algorithm (Preemptive)-->\n"); 28 | printf("Enter Number of Processes: "); 29 | scanf("%d",&n); 30 | for(int i=0;ip[j+1].at) 36 | { 37 | temp=p[j]; 38 | p[j]=p[j+1]; 39 | p[j+1]=temp; 40 | } 41 | min_val=p[0].temp,min_index=0; 42 | for(int j=0;j0) 54 | { 55 | min_val=p[0].temp,min_index=0; 56 | for(int j=0;j 2 | int n,q[10],front=-1,rear=-1; 3 | struct proc 4 | { 5 | int no,at,bt,ct,tat,wt,rt,completed; 6 | }; 7 | void enqueue(int i) 8 | { 9 | if(rear==10) 10 | printf("Overflow"); 11 | rear++; 12 | q[rear]=i; 13 | if(front==-1) 14 | front=0; 15 | } 16 | int dequeue() 17 | { 18 | if(front==-1) 19 | printf("Underflow"); 20 | int temp=q[front]; 21 | if(front==rear) 22 | front=rear=-1; 23 | else 24 | front++; 25 | return temp; 26 | } 27 | int isInQueue(int i) 28 | { 29 | int k; 30 | for(k=front;k<=rear;k++) 31 | { 32 | if(q[k]==i) 33 | return 1; 34 | } 35 | return 0; 36 | } 37 | struct proc read(int i) 38 | { 39 | struct proc p; 40 | printf("\nProcess No: %d\n",i); 41 | p.no=i; 42 | printf("Enter Arrival Time: "); 43 | scanf("%d",&p.at); 44 | printf("Enter Burst Time: "); 45 | scanf("%d",&p.bt); 46 | p.rt=p.bt; 47 | p.completed=0; 48 | return p; 49 | } 50 | void main() 51 | { 52 | int i,j,tq,time=0,remaining; 53 | float avgtat=0,avgwt=0; 54 | struct proc p[10],temp; 55 | printf("<--Round Robin (Queue Implementation) Scheduling Algorithm-->\n"); 56 | printf("Enter Number of Processes: "); 57 | scanf("%d",&n); 58 | printf("Enter Time Quantum: "); 59 | scanf("%d",&tq); 60 | for(int i=0;ip[j+1].at) 65 | { 66 | temp=p[j]; 67 | p[j]=p[j+1]; 68 | p[j+1]=temp; 69 | } 70 | remaining=n; 71 | enqueue(0); 72 | printf("\nQueue: "); 73 | for(time=p[0].at;remaining!=0;) 74 | { 75 | i=dequeue(); 76 | if(p[i].rt<=tq) 77 | { 78 | time+=p[i].rt; 79 | p[i].rt=0; 80 | p[i].completed=1; 81 | remaining--; 82 | printf("-> P%d",p[i].no); 83 | p[i].ct=time; 84 | p[i].tat=p[i].ct-p[i].at; 85 | avgtat+=p[i].tat; 86 | p[i].wt=p[i].tat-p[i].bt; 87 | avgwt+=p[i].wt; 88 | for(j=0;j P%d",p[i].no); 97 | for(j=0;j