Preemptive SJF

Page 1 of 1

2 Replies - 10891 Views - Last Post: 11 January 2011 - 11:33 AM Rate Topic: -----

#1 swagato29   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 14-February 09

Preemptive SJF

Posted 14 February 2009 - 02:24 PM

I am having problem running this code and it is not displaying the correct output....PLZ help me solve this problem by identifying the error in the logic....

#include<stdio.h>

void canx();
void main()
{
	

    canx();
}
void canx()
{
int i,j,Wt[10],B[10],A[10],Tt=0,l;
int n,Bu[20];

	char S[20],start[20];
	int max=0,Time=0,min;
	float Twt=0.0,Awt;
    printf("Enter the no of processes:");
	scanf("%d",&n);
	for(l=1;l<=n;l++)
	{
		printf("Enter The BurstTime for Process p %d =	",l);
		scanf("%d",&Bu[l]);
    }
	for(i=1;i<=n;i++)
	{
		B[i]=Bu[i];
		printf("\nBurst time for process P %d =	%d",i,B[i]);
		if(B[i]>max)
        
            max=B[i];
         
		Wt[i]=0;
		S[i]='T';
		start[i]='F';
		Tt=Tt+B[i];
		printf("\nEnter the Arrival Time for %d th process=	",i);
		scanf("%d",&A[i]);
		if(A[i]>Time)
			Time=A[i];
	}
printf("\nMax=%d",max);
	int w=0,flag=0,t=0;
	i=1;
	while(t<Time)
	{
		if(A[i]<=t && B[i]!=0)
		{
			if(flag==0)
			{
				Wt[i]=Wt[i]+w;
				printf("\nWt[%d]=%d",i,Wt[i]);
			}
			B[i]=B[i]-1;
			if(B[i]==0)
				S[i]='F';
			start[i]='T';
			t++;
			w=w+1;
			if(S[i]!='F')
			{
				j=1;flag=1;
				while(j<=n && flag!=0)
				{
					if(S[j]!='F' && B[i]>B[j] && A[j]<=t && i!=j )
					{
						flag=0;
						Wt[i]=Wt[i]-w;
						i=j;
					}
					else
					{
						flag=1;
					}
					j++;
				}
			}
			else
			{
				i++;
				j=1;
				while(A[j]<=t &&j<=n)
				{
					if(B[i]>B[j] && S[j]!='F')
					{
						flag=0;
						i=j;
					}
					j++;
				}
			}
		}
		else
			if(flag==0)
			i++;
	}


	printf("\nPrinting remaining burst time");
	for(i=1;i<=n;i++)
		printf("\nB[%d]=%d",i,B[i]);
	printf("                 ");

	while(w<Tt)
	{
		min=max+1;
		i=1;
		while(i<=n)
		{
			if(min>B[i] && S[i]=='T')
			{
				min=B[i];
				j=i;
			}
			i++;
		}
		i=j;
		if(w==Time && start[i]=='T')
		{   
            Wt[i]=Wt[i]+w;
			w=w+B[i];
			S[i]='F';
		}
		else
		{
			Wt[i]=Wt[i]+w;
			w=w+B[i];
			S[i]='F';
		}
	}

printf("\nWeight info");

	for(i=1;i<=n;i++)
		printf("\nWT[%d]=%d",i,Wt[i]);
printf("\nAfter subtracting arrival time");
	for(i=1;i<=n;i++)
	{
		Wt[i]=Wt[i]-A[i];
		printf("\nWT[%d]=%d",i,Wt[i]);
	}
	
}

This post has been edited by JackOfAllTrades: 11 January 2011 - 11:39 AM
Reason for edit:: Added code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Preemptive SJF

#2 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: Preemptive SJF

Posted 14 February 2009 - 07:30 PM

1. Code tags.
2. You need to tell us what you expect, vs. what you're receiving.
Was This Post Helpful? 0
  • +
  • -

#3 twenty two   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 29-May 10

Re: Preemptive SJF

Posted 11 January 2011 - 11:33 AM

I have solved the problm in ur code ......... ur post is 1 year later bt still if u need it reply...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1