question archive 'Data structure laboratory' has got 60 systems connected to a server and a printer

'Data structure laboratory' has got 60 systems connected to a server and a printer

Subject:Computer SciencePrice:3.87 Bought7

'Data structure laboratory' has got 60 systems connected to a server and a printer. After the coding gets over, the student wants to take a print out. The printer can serve only one person per time with a buffer to hold 10 programs at a time including the one that is printing at that time. Implement a C Program to automate the process of getting the files printed according to the time of arrival. Use an appropriate data structure. The printer at any time should show the list of files waiting for service.

here is an algorithm:

1.first Create a queue of print tasks. Each task will be given a timestamp upon its arrival. The queue is empty to start.

2.For each second (currentSecond):

  2.1 Does a new print task get created? If so, add it to the queue with the currentSecond as the timestamp.

  2.2 If the printer is not busy and if a task is waiting,

    Remove the next task from the print queue and assign it to the printer.

    Subtract the timestamp from the currentSecond to compute the waiting time for that task.

   Append the waiting time for that task to a list for later processing.

   Based on the number of pages in the print task, figure out how much time will be required.

 2.3 The printer now does one second of printing if necessary. It also subtracts one second from the time required for that task.

 2.4 If the task has been completed, in other words the time required has reached zero, the printer is no longer busy.

3.After the simulation is complete, compute the average waiting time from the list of waiting times generated.

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Answer Preview

Answer :-

First Come First Served (FCFS) is a Non-Preemptive scheduling algorithm. FIFO (First In First Out) strategy assigns

priority to process in the order in which they request the processor. The process that requests the CPU first is allocated

the CPU first. This is easily implemented with a FIFO queue for managing the tasks. As the process come in, they are put at

the end of the queue. As the CPU finishes each task, it removes it from the start of the queue and heads on to the next

task.

 

TERMS In First Come First Serve

  • Completion time: Time when the execution is completed.
  • Turn Around Time: The sum of the burst time and waiting time gives the turn-around time
  • Waiting time: The time the processes need to wait for it to get the CPU and start execution is called waiting time.

 

Important Points

  • It is non-preemptive
  • Average waiting time is not optimal
  • Cannot utilize resources in parallel

 

 

Program:-

 

#include<stdio.h> 

 int main()

 

{

  int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;

  printf("Enter total number of processes(maximum 20):");

  scanf("%d",&n);

 

  printf("nEnter Process Burst Timen");

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

  {

    printf("P[%d]:",i+1);

    scanf("%d",&bt[i]);

  }

 

  wt[0]=0;  

 

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

  {

    wt[i]=0;

    for(j=0;j<i;j++)

      wt[i]+=bt[j];

  }

 

  printf("nProcessttBurst TimetWaiting TimetTurnaround Time");

 

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

  {

    tat[i]=bt[i]+wt[i];

    avwt+=wt[i];

    avtat+=tat[i];

    printf("nP[%d]tt%dtt%dtt%d",i+1,bt[i],wt[i],tat[i]);

  }

 

  avwt/=i;

  avtat/=i;

  printf("nnAverage Waiting Time:%d",avwt);

  printf("nAverage Turnaround Time:%d",avtat);

  return 0;

}