#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();
}
#include
#include
#include
void main()
{
clrscr();
int bt[10],n,i,slot,totaltime=0;
cout<<"enter the number of processes:"<
cout<<"enter the time slot:"<
for(i=1;i<=n;i++)
{
cout<<"enter the burst time for process p"<cin>>bt[i];
}
cout<<"\n\nprocess\t\tburst-time"<
{
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();
}
#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(){
}
c program for shortest remaining time scheduling algo
C source code is portable; it can be compiled upon any machine with a suitable C compiler in order to produce the machine-dependant code (the machine code). However, C can also be used to write machine-dependant code, or code that is dependant upon specific platforms. In order to be completely portable, the code must use the C standard library and/or generic libraries.
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.
yes we can do it,in c
The Express edition of C++ does not require a serial code. It is free.
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.
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
why we use disk scheduling in c ?
Don C. Adams has written: 'Block scheduling' -- subject(s): Block scheduling (Education)
J. C. Thorpe has written: 'A comparison of vehicle scheduling methods'
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
A) client schedules B) migration schedules C) enterprise schedules D) Synchronized scheduling with IBM Tivoli Workload Scheduler
Sometimes, it is. Some implementations compile C++ code into C code, and then compile the C code.
i do no...............
c program for shortest remaining time scheduling algo
wat is the code for SUCTION d and c
A scheduler is the heart of every RTOS. It provides the algorithms to select the task for execution. Three common scheduling algorithms are > Cooperative scheduling > Round-robin scheduling > Preemptive scheduling RTOS uses preemptive (priority based) scheduling. In some cases, real-time requirements can be met by using static scheduling.