answersLogoWhite

0


Best Answer

#include<stdio.h>

#include<conio.h>

main()

{

int st[10],bt[10],wt[10],tat[10],n,tq;

int i,count=0,swt=0,stat=0,temp,sq=0;

float awt=0.0,atat=0.0;

clrscr();

printf("Enter number of processes:");

scanf("%d",&n);

printf("Enter burst time for sequences:");

for(i=0;i<n;i++)

{

scanf("%d",&bt[i]);

st[i]=bt[i];

}

printf("Enter time quantum:");

scanf("%d",&tq);

while(1)

{

for(i=0,count=0;i<n;i++)

{

temp=tq;

if(st[i]==0)

{

count++;

continue;

}

if(st[i]>tq)

st[i]=st[i]-tq;

else

if(st[i]>=0)

{

temp=st[i];

st[i]=0;

}

sq=sq+temp;

tat[i]=sq;

}

if(n==count)

break;

}

for(i=0;i<n;i++)

{

wt[i]=tat[i]-bt[i];

swt=swt+wt[i];

stat=stat+tat[i];

}

awt=(float)swt/n;

atat=(float)stat/n;

printf("Process_no Burst time Wait time Turn around time

");

for(i=0;i<n;i++)

printf("%d %d %d %d

",i+1,bt[i],wt[i],tat[i]);

printf("Avg wait time is %f

Avg turn around time is %f",awt,atat);

getch();

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

#include
#include
#include
void main()
{
clrscr();
int bt[10],n,i,slot,totaltime=0;
cout<<"enter the number of processes:"<cin>>n;
cout<<"enter the time slot:"<cin>>slot;
for(i=1;i<=n;i++)
{
cout<<"enter the burst time for process p"<cin>>bt[i];
}
cout<<"\n\nprocess\t\tburst-time"<for(i=1;i<=n;i++)
{
cout<<"\nP"<}
cout<<"\n\n";
i=1;
while(totaltime!=0)
{
for(i=1;i<=n;i++)
{
if(bt[i]>0)
{
cout<<"process p "<if(bt[i]>slot)
{
delay(slot*1000);
bt[i]-=slot;
totaltime-=slot;
}
else
{
delay(bt[i]*1000);
totaltime-=bt[i];
bt[i]=0;
cout<<"process p"<}
}
}
}
getch();
}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

#include<stdio.h>

#include<stdlib.h>

#include<pthread.h>

struct nodek {

int arrival_time;

int burst_time;

struct nodek *nextk;

struct nodek *prev;

int pid;

//int priority;

};

void disp(int count,struct nodek *last);

struct nodek *headk;

struct nodek *last;

struct nodek *last1;

int count=0,count1=0;//count1 pid counter;

int count3=0;//time counter

int time_quantum;

void runner(int *param);

void sjf();

void rr();

struct nodek *add(struct nodek *headk);

void main(){

int i;

printf("for fcfs press 1 ,for rr press 2 and for sjf press 3 to exit press 0");

while(1){

printf("enter number");

scanf("%d",&i);

if(i==1){

fcfs();

}

if(i==2){

rr();

}

if(i==3){

sjf();

}

if(i==0){

break ;

}

}

}

void rr(){

pthread_t th1;

pthread_attr_t attr;

int i;

int count;

struct nodek *temp;

headk=malloc(sizeof(struct nodek));

last=headk;

last1=last;

//newk=headk;

int n,j,m,flag,val,pos,status;

printf("\nenter time quantum:");

scanf("%d",&time_quantum);

printf("to intialize enter 3 processes\n");

n=3;

for(i=0;i<n-1;i++)

{

printf("enter the burst_time: ");

scanf("%d",&headk->burst_time);

headk->arrival_time=count1;

count3++;

temp=headk;

headk->nextk=malloc(sizeof(struct nodek));

headk=headk->nextk;

headk->prev=temp;

count1++;

temp->pid=count1;

count++;

}

printf("enter the burst_time: ");

scanf("%d",&headk->burst_time);

headk->arrival_time=count1;

headk->prev=temp;

count1++;

headk->pid=count1;

count++;

headk->nextk=last;

disp(count,last);

printf("to enter a process in between enter a\n");

printf("to continue rr enter 1:\n");

scanf("%d",&j);

while(j==1){

char c;

//assuming that the proceess comes one by one no two process come at the same time.

if(kbhit())

{

c = fgetc(stdin);

if(c=='a'){

count1++;

headk=add(headk);

count++;

disp(count,last);

fflush(stdin);

}

}

else{

pthread_create(&th1,NULL,&runner,(int *)&(last1->burst_time));

pthread_join(th1,NULL);

}

if(last==NULL){

break;

}

}

}

void runner(int *param){

int x,i;

char c;

struct nodek *temp;

x = *((int *) param);

for(i=0;i<time_quantum;i++){

if(kbhit())

{

c = fgetc(stdin);

if(c=='a'){

count1++;

headk=add(headk);

printf("%d\n",headk->burst_time);

disp(count1,last);

fflush(stdin);

}

}

sleep(1);

count3++;

last1->burst_time--;

if(last1->burst_time==0){

break;

}

}

printf("process:%d\n",last1->pid);

//if the first one gets deleted then last would actually point to null.

if(last1->burst_time==0){

struct nodek *flag=last1;

printf("process %d finished \n",flag->pid);

last1=last1->nextk;

last1->prev=flag->prev;

if(!(last==last1)){

(flag->prev)->nextk=last1;}

printf("kl\n");

free(flag);

if(last==NULL){

printf("hello\n");

last=last1;

}

printf("hell\n");

pthread_exit(0);

}

else{

last1=last1->nextk;

pthread_exit(0);

}

}

struct nodek *add(struct nodek *headk){

struct nodek *temp1=malloc(sizeof(struct nodek));

printf("enter the burst time of the process");

scanf("%d",&temp1->burst_time);

temp1->arrival_time=count3++;

temp1->nextk=headk->nextk;

headk->nextk=temp1;

temp1->prev=headk;

headk=temp1;

headk->pid=count1;

count1++;

headk->nextk=last;

return headk;

}

void disp(int count,struct nodek *last){

int j;

struct nodek *temp1=last;

for(j=0;j<count1;j++){

printf("count :%d,%d\n",count1,temp1->burst_time);

temp1=temp1->nextk;

}

}

void sjf(){

}

fcfs(){

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Code of Round-robin scheduling in c?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are the disadvantages of RoundRobin Scheduling?

Pure round robin scheduling processes A, then B, then C, then starts at A again. (A, B, C might be tasks in an operating system context, or devices in a master/slave control network, or whatever.) That is, pure round robin scheduling doesn't acknowledge priorities, and does not allow out-of-order processing. Real-life systems typically use a mixture of algorithms that, together, allow for prioritized and out-of-order processing while, on the other hand, trying to prevent starvation of lower priority items.


Why in round robin new processes place at end of queue rather than at beginning?

in roundrobin scheduling each process is gven a fixed time to execute so whenever a new process arrives it is placed at the end of the queue,,,,,the advantage by doing this type of scheduling is response time will be gud...But the disadvantage waiting time is more


What is disk scheduling in operating system?

why we use disk scheduling in c ?


What has the author Don C Adams written?

Don C. Adams has written: 'Block scheduling' -- subject(s): Block scheduling (Education)


What has the author J C Thorpe written?

J. C. Thorpe has written: 'A comparison of vehicle scheduling methods'


What has the author Steven C Kleiner written?

Steven C. Kleiner has written: 'Distribution of a generic mission planning and scheduling toolkit for astronomical spacecraft' -- subject(s): Scheduling, Mission planning, Spaceborne astronomy, Launch vehicles


Which type of scheduling are part of the IBM Tivoli Storage Manager server?

A) client schedules B) migration schedules C) enterprise schedules D) Synchronized scheduling with IBM Tivoli Workload Scheduler


Is C plus plus preprocessor software?

Sometimes, it is. Some implementations compile C++ code into C code, and then compile the C code.


What is local scheduling and global scheduling?

i do no...............


Compute the average waiting time and average turnaround time for each what scheduling algorithms and determine which one gives the best results. a.FCFS b.SJN c.SRT d.round robin?

c program for shortest remaining time scheduling algo


Suction d and c cpt code?

wat is the code for SUCTION d and c


What type of scheduling is there in RTOS?

A scheduler is the heart of every RTOS. It provides the algorithms to select the task for execution. Three common scheduling algorithms are &gt; Cooperative scheduling &gt; Round-robin scheduling &gt; Preemptive scheduling RTOS uses preemptive (priority based) scheduling. In some cases, real-time requirements can be met by using static scheduling.