scheduling program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cyrine
    New Member
    • Feb 2008
    • 4

    scheduling program

    im looking for a codes of scheduling w/c is shortest job first(non preEmptive) in operating system using a c++ language..
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Well, aside of posting in the wrong forum, what do you have so far?

    Comment

    • cyrine
      New Member
      • Feb 2008
      • 4

      #3
      Originally posted by sicarie
      Well, aside of posting in the wrong forum, what do you have so far?

      a code using visual basic.. first come first serve
      i want to translate this into turbo C++ but shortest job first NP

      Comment

      • Meetee
        Recognized Expert Contributor
        • Dec 2006
        • 928

        #4
        Originally posted by cyrine
        a code using visual basic.. first come first serve
        i want to translate this into turbo C++ but shortest job first NP
        Yes, agree! But you need to read posting guidelines. We do not provide direct code in this community. Scheduling algorithm's algorithms are easily available by searching google. You can apply logic accordingly. Kindly narrate your problem here if you find any.

        Regards

        Comment

        • cyrine
          New Member
          • Feb 2008
          • 4

          #5
          Originally posted by zodilla58
          Yes, agree! But you need to read posting guidelines. We do not provide direct code in this community. Scheduling algorithm's algorithms are easily available by searching google. You can apply logic accordingly. Kindly narrate your problem here if you find any.

          Regards

          pls help me to translate this into a visual basic language..

          // PROGRAM FOR SJF - NON PREEMPTIVE SCHE
          // DULING ALGORITHM
          //PREPROCESSOR DIRECTIVES
          #include<stdio. h>
          #include<conio. h>
          #include<string .h>
          #include<iostre am.h>
          //GLOBAL VARIABLES - DECLARATION
          int Twt,Ttt,A[20],Wt[20],n,Bu[20];
          float Att,Awt;
          char pname[20][20];
          //FUNCTION DECLARATIONS
          void Getdata();
          void Gantt_chart();
          void Sjf();
          //GETTING THE NUMBER OF PROCESSES AND TH
          // E BURST TIME AND ARRIVAL TIME FOR EACH P
          // ROCESS
          void Getdata()


          {
          int i;
          cout<<"\n Enter the number of processes: ";
          cin>>n;
          for(i=1;i<=n;i+ +)


          {
          fflush(stdin);
          cout<<"\n\n Enter the process name: ";
          cin>>pname[i];
          cout<<"\n Enter The BurstTime for Process: "<<pname[i]<<endl;
          cin>>Bu[i];
          cout<<"\n Enter the Arrival Time for Process: "<<pname[i]<<endl;
          cin>>A[i];
          }
          }

          //DISPLAYING THE GANTT CHART
          void Gantt_chart()


          {
          int i;
          cout<<"\n\nGANT T CHART";
          cout<<"\n--------------------------------------------------------------------\n"<<endl;
          for(i=1;i<=n;i+ +)
          cout<<pname[i];
          cout<<"|\t\n";
          cout<<"\n-----------------------------------------------------------\n";
          cout<<"\n"<<end l;
          for(i=1;i<=n;i+ +)
          cout<<Wt[i]<<endl;
          cout<<Wt[n]+Bu[n]<<endl;
          cout<<"\n--------------------------------------------------------------------\n";
          cout<<"\n";
          }

          //Shortest job First Algorithm with NonPreemption
          void Sjf()


          {
          int w,t,i,B[10],Tt=0,temp,j;
          char S[10],c[20][20];
          int temp1;
          cout<<"\n\n SHORTEST JOB FIRST SCHEDULING ALGORITHM \n\n"<<endl;
          Twt=Ttt=0;
          w=0;
          for(i=1;i<=n;i+ +)


          {
          B[i]=Bu[i];
          S[i]='T';
          Tt=Tt+B[i];
          }
          for(i=1;i<=n;i+ +)


          {
          for(j=3;j<=n;j+ +)


          {
          if(B[j-1]>B[j])


          {
          temp=B[j-1];
          temp1=A[j-1];
          B[j-1]=B[j];
          A[j-1]=A[j];
          B[j]=temp;
          A[j]=temp1;
          strcpy(c[j-1],pname[j-1]);
          strcpy(pname[j-1],pname[j]);
          strcpy(pname[j],c[j-1]);
          }
          }
          }
          //For the 1st process
          Wt[1]=0;
          w=w+B[1];
          t=w;
          S[1]='F';
          while(w<Tt)


          {
          i=2;
          while(i<=n)


          {
          if(S[i]=='T'&&A[i]<=t)


          {
          Wt[i]=w;
          S[i]='F';
          w=w+B[i];
          t=w;
          i=2;
          }
          else
          i++;
          }
          }
          //CALCULATING AVERAGE WAITING TIME AND AVERAGE TURN AROUND TIME
          for(i=1;i<=n;i+ +)


          {
          Twt=Twt+(Wt[i]-A[i]);
          Ttt=Ttt+((Wt[i]+Bu[i])-A[i]);
          }
          Att=(float)Ttt/n;
          Awt=(float)Twt/n;
          cout<<"\n\n Average Turn around time=%3.2f ms "<<Att;
          cout<<"\n\n AverageWaiting Time=%3.2f ms"<<Awt;
          Gantt_chart();
          }

          void main()


          {
          clrscr();
          Getdata();
          Sjf();
          getch();
          }

          Comment

          Working...