title: OS time scheduling program
body: <p>I making a program for my subject, OS time scheduling program written in C language. I'm just starting it out but my problem is how to display the GANTT chart. And I'm little bit confuse about the Preemptive First Come, First Serve. I understand how it works but when it comes if the ARRIVAL time is...</p>
  
  <pre><code>PROCESS  BURST TIME   ARRIVAL TIME  START   WAITING   FINISH   TURN AROUND TIME
  P1         12            2            ?????
  P2         6             1            ?????
  P3         9             0            ?????
  </code></pre>
  
  <p>but if the arrival time start in 0, I know how to answer it...</p>
  
  <pre><code>PROCESS  BURST TIME   ARRIVAL TIME  START   WAITING   FINISH   TURN AROUND TIME
  P1         12            0            0      0         12           12
  P2         6             1            12     11        18           17
  P3         9             4            18     14        27           23
  
  average waiting time = 8.33
  average turn around time= 17.33
  </code></pre>
  
  <p>here my code, I just got some of my code to the internet. Its not yet done only the FCFS code I have....</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt; 
  
  //FCFS
  void npefcfs();
  void pefcfs();
  void fcfs();
  //MENU
  void menu();
  //y/n statement
  void backq();
  
  
  int main()
  {
  menu();
  system("pause");
  return 0;
  }
  
  void menu()
  {
  int choose;
  printf("    MENU OS Time Scheduling Discipline");
  printf("\n  ---------------------------------------------------");
  printf("\n  [1] (FCFS)First Come, First Serve");
  printf("\n  [2] (SJF)Shortest Job First");
  printf("\n  [3] (SRT)Shortest Remaining Time");
  printf("\n  [4] (RR)Round-robin Scheduling");
  printf("\n  [5] (MLQ)Multilevel queue scheduling");
  printf("\n  [6] Priority");
  printf("\n  [7] EXIT");
  printf("\n\nEnter your choice: ");
  scanf("%d", &amp;choose);
  switch (choose)
  {
  case 1:
      system("cls");
      fcfs();
      break;
  case 7:
      break;
  default:
      system("cls");
      printf("Please Enter Correct Value!\n\n");
      menu();
      break;
  }
  
  }
  
  //y/n statement
  void backq()
  {
  char choice2;
  printf("Do you like another try? y/n, Y/N: ");
  scanf("%s", &amp;choice2);
  switch (choice2)
  {
  case 'y':
      system("cls");
      menu();
      break;
  case 'Y':
      system("cls");
      menu();
      break;
  case 'n':
      system("exit");
      break;
  case 'N':
      system("exit");
      break;
  default:
      system("cls");
      printf("\nPlease Enter a coorect value!");
      backq();
      break;
  }
  }
  
  //fcfs menu
  void fcfs()
  {
  int choice;
  printf("FIRST COME, FIRST SERVE");
  printf("\n-----------------------------");
  printf("\n  [1] Non Pre-emptive");
  printf("\n  [2] Pre-emptive");
  printf("\n  [3] BACK");
  printf("\n  [4] Exit");
  printf("\nPlease your choice: ");
  scanf("%d",&amp;choice);
  switch (choice)
  {
  case 1:
      system("cls");
      npefcfs();
      break;
  case 2:
      system("cls");
      pefcfs();
      break;
  case 3:
      system("cls");
      menu();
      break;
  case 4:
      break;
  default:
      break;
  }
  }
  //function for non pre-emptive fcfs
  void npefcfs()
  {
  //declaration
  int process;
  int bt[10], at[10], start[10], wait[10], fnsh[10], ta[10];
  int i, a, sum = 0;
  float awt=0.0, att=0.0;
  start[0] = 0;
  //how many process
  printf("How many process do you like to use: ");
  scanf("%d",&amp;process);
  printf("\n-----------------------------------------");
  printf("\nPlease Enter Burst time: \n\n");
  
  //for declaring zero to at[] array
  for(i=0; i&lt;process; i++)
  {
      at[i]=0;
  }
  //enter burst time depending on how many process
  for (i = 0, a=1; i &lt; process,a&lt;=process; i++,a++)
  {
      printf("P%d =",a);
      scanf("%d", &amp;bt[i]);
  }
  //for calculation of fcfs
  for(i=0; i&lt;process; i++)
  {
      sum=0;
      for(a=0; a&lt;i; a++)
      {
          sum=sum+bt[a];
          start[i]=sum;
      }
  }
  //for calculation of start,wait,finish,turn around time, average waiting time and average turn around time
  for(i=0; i&lt;process; i++)
  {
      wait[i] = start[i];
      fnsh[i] = bt[i]+start[i];
      ta[i] = fnsh[i];
      awt+=wait[i];
      att+=ta[i];
  }
  //computation
  awt/=process;
  att/=process;
  
  //output in table like form
  printf("\n\tProcess\tBT\tAT\tSTART\tWAIT\tFINISH\tTA");
  printf("\n\t-------\t--\t--\t-----\t----\t------\t--");
  for(i=0; i&lt;process; i++)
  {
      printf("\n\tP%d\t%d\t%d\t%d\t%d\t%d\t%d", (i+1),bt[i],at[i],start[i],wait[i],fnsh[i],ta[i]);
  }
  printf("\n\nAverage Waiting Time: %f", awt);
  printf("\nAverage Turn Around Time: %f\n",att);
  backq();
  }
  //function for pre-emptive fcfs
  void pefcfs()
  {
  //declaration
  int process;
  int bt[10], at[10], start[10], wait[10], fnsh[10], ta[10];
  int i, a, sum = 0;
  float awt=0.0, att=0.0;
  start[0] = 0;
  //how many process
  printf("How many process do you like to use: ");
  scanf("%d",&amp;process);
  printf("\n-----------------------------------------");
  printf("\nPlease Enter Burst Time: \n\n");
  
  //enter burst time depending on how many process
  for (i = 0, a=1; i &lt; process,a&lt;=process; i++,a++)
  {
      printf("P%d =",a);
      scanf("%d", &amp;bt[i]);
  }
  printf("\nPlease Enter Arrival Time: \n");
  
  //enter arrival time
  for(i=0; i&lt;process; i++)
  {
      printf("AT%d =", (i+1));
      scanf("%d", &amp;at[i]);
  }
  
  //for calculation of fcfs
  for(i=0; i&lt;process; i++)
  {
      sum=0;
      for(a=0; a&lt;i; a++)
      {
          sum=sum+bt[a];
          start[i]=sum;
      }
  }
  //for calculation of start,wait,finish,turn around time, average waiting time and average turn around time
  for(i=0; i&lt;process; i++)
  {
      wait[i] = start[i]-at[i];
      fnsh[i] = bt[i]+start[i];
      ta[i] = fnsh[i]-at[i];
      awt+=wait[i];
      att+=ta[i];
  }
  //computation
  awt/=process;
  att/=process;
  
  //output in table like form
  printf("\n\tProcess\tBT\tAT\tSTART\tWAIT\tFINISH\tTA");
  printf("\n\t-------\t--\t--\t-----\t----\t------\t--");
  for(i=0; i&lt;process; i++)
  {
      printf("\n\tP%d\t%d\t%d\t%d\t%d\t%d\t%d", (i+1),bt[i],at[i],start[i],wait[i],fnsh[i],ta[i]);
  }
  printf("\n\nAverage Waiting Time: %f", awt);
  printf("\nAverage Turn Around Time: %f\n",att);
  backq();
  }
  </code></pre>
  
  <p>And I don't know how to display the GANTT chart depending on the burst time like for example</p>
  
  <pre><code>______________________________
  |     p1      |    p2   | p3 |
  |_____________|_________|____|
  0             12        18    27
  </code></pre>