PeakNotes - Your Ultimate Resource for Coding Tips and Tutorials

operating system lab

                        OS lab programs

 

Question 2/* AIM :to write a c prog to simulate the cpu sheduling algo first come

first serve(FCFS)*/

 

#include<stdio.h>
#include<conio.h>
 void main()
 {
    int bt[20],wt[20],tat[20],i,n;
    float wtavg, tatavg;
   
    printf("\n Enter no of processes");
    scanf("%d",&n);
      for (i=0;i<n;i++)
      {
        printf("enter burst time for process %d:",i);
        scanf("%d",&bt[i]);
      }
      wt[0]=wtavg=0;
      tat[0]=tatavg=bt[0];
     for (i=1;i<n;i++)
       {
        wt[i]=wt[i-1]+bt[i-1];
        tat[i]=tat[i-1]+bt[i];
        wtavg = wtavg+wt[i];
        tatavg = tatavg + tat[i];
       }


     printf("process \t brust time \t waiting time\t turnaround time \n");
     
       for(i=0;i<n;i++)
     printf("\n \t \t %d \t\t%d \t\t%d \t\t%d",i,bt[i],wt[i],tat[i]);
     printf("\n average waiting time :%f",wtavg/n);
     printf("\n average turnaround time :%f",tatavg/n);
und
     getch();  

 }

Output

Enter no of processes3 enter burst time for process 0:24 enter burst time for process 1:3 enter burst time for process 2:3 process burst time waiting time turnaround time 0 24 0 24 1 3 24 27 2 3 27 30 average waiting time :17.000000 average turnaround time :27.000000

Algorithm
1. start the process
2. Accept the number of processes in the ready queue.
3. For each process in the ready queue assign the process id and the
burst time.
4. set the waiting time of the first process as=0 and its burst time as its
turnaround time.
5. for each process in the ready queue calculate
a)waiting time(n)=waiting time(n-1)+burst time(n-1)
b)turnaround time(n)= turnaround time(n-1)+ burst time(n)
6. calculate
a)Average waiting time= total waiting time/no. of process
b)Average turnaround time= total turnaround time/no. of process



Question 3


/* aim : */
 #include<stdio.h>
 #include<conio.h>
 
   void main()
   {
     int p[20],bt[20],wt[20],tat[20],i,n,k,temp;
    float wtavg, tatavg;
   
    printf("\n Enter no of processes");
    scanf("%d",&n);
       for(i=0;i<n;i++)
       {
        p[i]=i;
        printf("Enter burst time of process %d",i);
        scanf("%d",&bt[i]);
       }

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

              if(bt[i]>bt[k])
              {
                temp=bt[i];
                bt[i]=bt[k];
                bt[k]=temp;
                temp=p[i];
                p[i]=p[k];
                p[k]=temp;
              }

              wt[0]=wtavg=0;
              tat[0]=tatavg=bt[0];
     for (i=1;i<n;i++)
       {
        wt[i]=wt[i-1]+bt[i-1];
        tat[i]=tat[i-1]+bt[i];
        wtavg = wtavg+wt[i];
        tatavg = tatavg + tat[i];
       }

     printf("process \t brust time \t waiting time\t
turnaround time \n");
     
       for(i=0;i<n;i++)
printf("\n \t \t p%d \t\t%d \t\t%d \t\t%d",
p[i],bt[i],wt[i],tat[i]);
      printf("\n average waiting time %f",wtavg/n);
     printf("\n average waiting time %f",tatavg/n);

     getch();
   }

Output
Enter no of processes3 Enter burst time of process24 Enter burst time of process3 Enter burst time of process3 process burst time waiting time turnaround time p1 3 0 3 p2 3 3 6 p0 24 6 30 average waiting time 3.000000 average turnaround time 13.000000



Algorithm
1. start the process
2. Accept the number of processes in the ready queue.
3. For each process in the ready queue assign the process id and the
burst time.
4. start the ready Q assign the shortest burst time by sorting according to lowest
to highest burst time.
5. set the waiting of the first process 0 and its turnaround time as the burst time.
6. sort the process name based on their burst time.
7. for each process in the ready Queue calculate
a)waiting time(n)=waiting time(n-1)+burst time(n-1)
b)turnaround time(n)= turnaround time(n-1)+ burst time(n)
8. calculate
c)average waiting time=total waiting time/number of process
b)average turnaround time = total turnaround time/ number of process
9. Stop the process.

Post a Comment

0 Comments