Professional Documents
Culture Documents
C Code
C Code
#include<stdio.h>
int main()
{
int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;
printf("Enter total number of processes(maximum 20):");
scanf("%d",&n);
avwt/=i;
avtat/=i;
printf("\n\nAverage Waiting Time:%d",avwt);
printf("\nAverage Turnaround Time:%d",avtat);
return 0;
}
#include<iostream>
int main()
{
int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;
cout<<"Enter total number of processes(maximum 20):";
cin>>n;
cout<<"\nEnter Process Burst Time\n";
for(i=0;i<n;i++)
{
cout<<"P["<<i+1<<"]:";
cin>>bt[i];
}
avwt/=i;
avtat/=i;
cout<<"\n\nAverage Waiting Time:"<<avwt;
cout<<"\nAverage Turnaround Time:"<<avtat;
return 0;
}
//////////////////////////////////////////////////
SJFS
#include<stdio.h>
void main()
{
int bt[20],p[20],wt[20],tat[20],i,j,n,total=0,pos,temp;
float avg_wt,avg_tat;
printf("Enter number of process:");
scanf("%d",&n);
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;
temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}
total+=wt[i];
}
/////////////////////////////////////////////////
RR
#include<stdio.h>
int main()
{
int count,j,n,time,remain,flag=0,time_quantum;
int wait_time=0,turnaround_time=0,at[10],bt[10],rt[10];
printf("Enter Total Process:\t ");
scanf("%d",&n);
remain=n;
for(count=0;count<n;count++)
{
printf("Enter Arrival Time and Burst Time for Process Process Number
%d :",count+1);
scanf("%d",&at[count]);
scanf("%d",&bt[count]);
rt[count]=bt[count];
}
printf("Enter Time Quantum:\t");
scanf("%d",&time_quantum);
printf("\n\nProcess\t|Turnaround Time|Waiting Time\n\n");
for(time=0,count=0;remain!=0;)
{
if(rt[count]<=time_quantum && rt[count]>0)
{
time+=rt[count];
rt[count]=0;
flag=1;
}
else if(rt[count]>0)
{
rt[count]-=time_quantum;
time+=time_quantum;
}
if(rt[count]==0 && flag==1)
{
remain--;
printf("P[%d]\t|\t%d\t|\t%d\n",count+1,time-at[count],time-at[count]-
bt[count]);
wait_time+=time-at[count]-bt[count];
turnaround_time+=time-at[count];
flag=0;
}
if(count==n-1)
count=0;
else if(at[count+1]<=time)
count++;
else
count=0;
}
printf("\nAverage Waiting Time= %f\n",wait_time*1.0/n);
printf("Avg Turnaround Time = %f",turnaround_time*1.0/n);
return 0;
}
//////////////////////////////////////////
SRTF
int main()
{
waiting[i] = 0;
total += bur[i];
temp = ari[i];
ari[i] = ari[j];
ari[j] = temp;
temp = bur[i];
bur[i] = bur[j];
bur[j] = temp;
{
small = 3200;
small = bur[j];
k = j;
bur[k]--;
procs[i] = k;
k = 0;
if (procs[i] == j)
finish[j] = i;
waiting[j]++;
return 0;
/////////////////////////////////////
PRIORITY
#include<stdio.h>
int main()
{
int bt[20],p[20],wt[20],tat[20],pr[20],i,j,n,total=0,pos,temp,avg_wt,avg_tat;
printf("Enter Total Number of Process:");
scanf("%d",&n);
//sorting burst time, priority and process number in ascending order using
selection sort
for(i=0;i<n;i++)
{
pos=i;
for(j=i+1;j<n;j++)
{
if(pr[j]<pr[pos])
pos=j;
}
temp=pr[i];
pr[i]=pr[pos];
pr[pos]=temp;
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;
temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}
total+=wt[i];
}
return 0;
}
////////////////////////////////////
full project
#include<stdio.h>
#include<stdlib.h>
// FCFS Algorithm
void FCFS(processes P[],int n){
processes temp[10];
int sumw=0,sumt=0;
int x = 0;
float avgwt=0.0,avgta=0.0;
int i,j;
for(i=0;i<n;i++)
temp[i]=P[i];
b_sort(temp,n);
printf("\n\n PROC.\tB.T.\tA.T.");
for(i=0;i<n;i++)
printf("\n %s\t%d\t%d",temp[i].name,temp[i].bt,temp[i].at);
sumw = temp[0].wt = 0;
sumt = temp[0].ta = temp[0].bt - temp[0].at;
for(i=1;i<n;i++){
temp[i].wt = (temp[i-1].bt + temp[i-1].at + temp[i-1].wt) -
temp[i].at;;
temp[i].ta = (temp[i].wt + temp[i].bt);
sumw+=temp[i].wt;
sumt+=temp[i].ta;
}
avgwt = (float)sumw/n;
avgta = (float)sumt/n;
printf("\n\n PROC.\tB.T.\tA.T.\tW.T\tT.A.T");
for(i=0;i<n;i++)
printf("\n %s\t%d\t%d\t%d\t
%d",temp[i].name,temp[i].bt,temp[i].at,temp[i].wt,temp[i].ta);
printf("0\t");
for(i=1;i<=n;i++){
x+=temp[i-1].bt;
printf("%d ",x);
}
printf("\n\n Average waiting time = %0.2f\n Average turn-around =
%0.2f.",avgwt,avgta);
}
for(i=0;i<n;i++)
temp[i]=P[i];
b_sort(temp,n);
for(i=2;i<n;i++)
for(j=1;j<n-i+1;j++){
if(temp[j].bt > temp[j+1].bt){
t = temp[j];
temp[j] = temp[j+1];
temp[j+1] = t;
}
}
printf("\n\n PROC.\tB.T.\tA.T.");
for(i=0;i<n;i++)
printf("\n %s\t%d\t%d",temp[i].name,temp[i].bt,temp[i].at);
sumw = temp[0].wt = 0;
sumt = temp[0].ta = temp[0].bt - temp[0].at;
for(i=1;i<n;i++){
temp[i].wt = (temp[i-1].bt + temp[i-1].at + temp[i-1].wt) -
temp[i].at;;
temp[i].ta = (temp[i].wt + temp[i].bt);
sumw+=temp[i].wt;
sumt+=temp[i].ta;
}
avgwt = (float)sumw/n;
avgta = (float)sumt/n;
printf("\n\n PROC.\tB.T.\tA.T.\tW.T\tT.A.T");
for(i=0;i<n;i++)
printf("\n %s\t%d\t%d\t%d\t
%d",temp[i].name,temp[i].bt,temp[i].at,temp[i].wt,temp[i].ta);
printf("0\t");
for(i=1;i<=n;i++){
x+=temp[i-1].bt;
printf("%d ",x);
}
printf("\n\n Average waiting time = %0.2f\n Average turn-around =
%0.2f.",avgwt,avgta);
}
for(i=0;i<n;i++)
temp[i]=P[i];
b_sort(temp,n);
for(i=2;i<n;i++)
for(j=1;j<n-i+1;j++){
if(temp[j].prt > temp[j+1].prt){
t = temp[j];
temp[j] = temp[j+1];
temp[j+1] = t;
}
}
printf("\n\n PROC.\tB.T.\tA.T.");
for(i=0;i<n;i++)
printf("\n %s\t%d\t%d",temp[i].name,temp[i].bt,temp[i].at);
sumw = temp[0].wt = 0;
sumt = temp[0].ta = temp[0].bt - temp[0].at;
for(i=1;i<n;i++){
temp[i].wt = (temp[i-1].bt + temp[i-1].at + temp[i-1].wt) -
temp[i].at;;
temp[i].ta = (temp[i].wt + temp[i].bt);
sumw+=temp[i].wt;
sumt+=temp[i].ta;
}
avgwt = (float)sumw/n;
avgta = (float)sumt/n;
printf("\n\n PROC.\tB.T.\tA.T.\tW.T\tT.A.T");
for(i=0;i<n;i++)
printf("\n %s\t%d\t%d\t%d\t
%d",temp[i].name,temp[i].bt,temp[i].at,temp[i].wt,temp[i].ta);
printf("0\t");
for(i=1;i<=n;i++){
x+=temp[i-1].bt;
printf("%d ",x);
}
printf("\n\n Average waiting time = %0.2f\n Average turn-around =
%0.2f.",avgwt,avgta);
}
for(i=0;i<n;i++)
temp1[i]=P[i];
b_sort(temp1,n);
for(i=0;i<n;i++)
temp2[i]=temp1[i];
for(k=0;;k++){
if(k>n-1)
k=0;
if(temp1[k].bt>0)
printf(" %d %s",tcurr,temp1[k].name);
t=0;
while(t<Q && temp1[k].bt > 0){
t++;
tcurr++;
temp1[k].bt--;
}
if(temp1[k].bt <= 0 && temp1[k].flag != 1){
temp1[k].wt = tcurr - temp2[k].bt - temp1[k].at;
temp1[k].ta = tcurr - temp1[k].at;
pflag++;
temp1[k].flag = 1;
sumw+=temp1[k].wt;
sumt+=temp1[k].ta;
}
if(pflag == n)
break;
}
printf(" %d",tcurr);
avgwt = (float)sumw/n;
avgta = (float)sumt/n;
printf("\n\n Average waiting time = %0.2f\n Average turn-around =
%0.2f.",avgwt,avgta);
}
//Shortest Job First - Pre-emptive
void SJF_P(processes P[],int n){
int i,t_total=0,tcurr,b[10],min_at,j,x,min_bt;
int sumw=0,sumt=0;
float avgwt=0.0,avgta=0.0;
processes temp[10],t;
for(i=0;i<n;i++){
temp[i]=P[i];
t_total+=P[i].bt;
}
b_sort(temp,n);
for(i=0;i<n;i++)
b[i] = temp[i].bt;
i=j=0;
printf("\n GANTT CHART\n\n %d %s",i,temp[i].name);
for(tcurr=0;tcurr<t_total;tcurr++){
if(i!=j)
printf(" %d %s",tcurr,temp[i].name);
temp[i].flag = 1;
temp[i].wt = (tcurr+1) - temp[i].bt - temp[i].at;
temp[i].ta = (tcurr+1) - temp[i].at;
sumw+=temp[i].wt;
sumt+=temp[i].ta;
}
j=i; min_bt = 999;
for(x=0;x<n;x++){
}
printf(" %d",tcurr);
avgwt = (float)sumw/n; avgta = (float)sumt/n;
printf("\n\n Average waiting time = %0.2f\n Average turn-around =
%0.2f.",avgwt,avgta);
}
for(i=0;i<n;i++){
temp[i]=P[i];
t_total+=P[i].bt;
}
b_sort(temp,n);
for(i=0;i<n;i++)
b[i] = temp[i].bt;
i=j=0;
printf("\n GANTT CHART\n\n %d %s",i,temp[i].name);
for(tcurr=0;tcurr<t_total;tcurr++)
{
if(i!=j)
printf(" %d %s",tcurr,temp[i].name);
}
printf(" %d",tcurr);
avgwt = (float)sumw/n;
avgta = (float)sumt/n;
printf("\n\n Average waiting time = %0.2f\n Average turn-around =
%0.2f.",avgwt,avgta);
}
int main(){
processes P[10];
int ch,n;
do{
printf("\n\n SIMULATION OF CPU SCHEDULING ALGORITHMS\n");
printf("\n Options:");
printf("\n 0. Enter process data.");
printf("\n 1. FCFS");
printf("\n 2. SJF (Pre-emptive)");
printf("\n 3. SJF (Non Pre-emptive)");
printf("\n 4. Priority Scheduling (Pre-emptive)");
printf("\n 5. Priority Scheduling (Non Pre-emptive)");
printf("\n 6. Round Robin");
printf("\n 7. Exit\n Select : ");
scanf("%d",&ch);
switch(ch){
case 0:
n=accept(P);
break;
case 1:
FCFS(P,n);
break;
case 2:
SJF_P(P,n);
break;
case 3:
SJF_NP(P,n);
break;
case 4:
PRT_P(P,n);
break;
case 5:
PRT_NP(P,n);
break;
case 6:
RR(P,n);
break;
case 7:exit(0);
}
}while(ch != 7);
getch();
return 0;
}
////////////////////////
A drive cannot make a motor produce more than its maximum torque. Max torque or
Stall Torque is generally not shown on the motor's nameplate. The iron in the motor
can only sustain a certain amount of magnetic flux density, even if iron is driven
harder, the flux density will not go up.
Benefits of AC drive
As AC drive usage in HVAC applications has increased, fans, pumps, air handlers,
and chillers can benefit from speed control. AC drives provide the following basic
advantages:
energy savings
low motor starting current
reduction of thermal and mechanical stresses on motors and belts during starts
simple installation
high power factor
lower KVA
single-phase-OEM-drive
SINGLE PHASE OEM DRIVE DESIGNED BY INVENTION HOUSE
A VFD can make a motor run slower than rated speed, however a major point of
consideration at low speed is cooling. A typical electric motor is cooled by a fan
on its shaft; at low speed the fan moves less air and at some point the motor will
over heat. This is generally not a problem with centrifugal loads such as fans,
pumps, and blowers because the torque required by the load drops drastically with
decreasing speed. In this case, the motor is doing less work, and there is less
waste heat to dispose of.
A VFD can drive a motor faster than its nameplate speed, however, above the rated
speed, the motor looses torque (twisting force). At higher speeds, less and less
torque is possible. The maximum continuous power (speed times torque) is limited by
the motor design, therefore a VFD cannot deliver more power than which the motor is
thermally capable.
A VFD can also make a motor more efficient, but only at reduced load and/or reduced
speed. A drive system will not use less power when the motor is running at rated
speed and rated load. In fact, it uses slightly more due to the losses within the
drive.
A VFD can make a motor reverse without the use of contactors, but it can’t make the
reversal faster than the combination of the motor’s max torque and the load’s
inertia allows.
A VFD can make a motor produce more than its rated torque but only briefly. The
amount of time is limited by either the drive’s overload capacity or the motor’s
thermal capacity. A drive cannot make a motor produce more than its maximum torque.
Max torque or Stall Torque is generally not shown on the motor’s nameplate. The
iron in the motor can only sustain a certain amount of magnetic flux density, even
if iron is driven harder, the flux density will not go up. The amount of torque a
motor creates at the flux limit is the most torque that can be achieved.