Question

In: Computer Science

1. Practice Tasks Aims: to simulate the principles and key technology in operating systems. You need...

1. Practice Tasks

Aims: to simulate the principles and key technology in operating systems. You need to analyze, design, implement and debug a program which simulates the chosen principles or technology. You need to finish the following tasks to do the practice:

1) CPU scheduling algorithms (including FCFS, SJF, Priority Scheduling, Round Robin)

2) Process Synchronization (including producer and consumer problem, reader and writer problem, Dining-Philosophers Problem)

3) Page replacement algorithm (including FIFO, LRU, Optimal Algorithm)

4) Disk scheduling algorithm (including FCFS, SSTF, SCAN)

You need to implement the above 4 tasks to do the practice. You need to implement the input, algorithms and the output. The output will be different when you switch to different algorithms.

2. Requirements

1) Requirement analysis

2) Function design

3) Code preferebly in c/c++ or java

4) Report write-up

Solutions

Expert Solution

(Please do rate the answer if you found useful - Solution for first question is only provided )

1) FCFS Program code:

#include<stdio.h>

int n,i,b[10],wt[10],tat[10];

void main()
{
   printf("enter no of process");
   scanf("%d",&n);
   for(i=0;i<n;i++)
   {  
       printf("enter burst time of process %d :",i);
       scanf("%d",&b[i]);
   }
   for(i=0;i<n;i++)
   { printf("\nthe waiting time of process %d :",i);
       wt[i]=b[i-1]+wt[i-1];
       printf("%d",wt[i]);
       printf("\nthe turn around time of process %d :",i);
       tat[i]=wt[i]+b[i];
       printf("%d",tat[i]);
   }
}


Output

2) SJF Program Code:

#include<stdio.h>

int n,i,b[10],wt[10],tat[10],j,temp;

void main()
{
   printf("enter no of process");
   scanf("%d",&n);
   for(i=0;i<n;i++)
   {
       printf("enter burst time of process %d :",i);
       scanf("%d",&b[i]);
   }
   for(i=0;i<n;i++)
   {
       for(j=0;j<n-1;j++)
       {
       if(b[j+1]<b[j])
       {
           temp=b[j];
           b[j]=b[j+1];
           b[j+1]=temp;
       }

   }
   }
   for(i=0;i<n;i++)
       printf("%d",b[i]);
       printf("\n");

   for(i=0;i<n;i++)
   { printf("\nthe waiting time of process %d :",i);
       wt[i]=b[i-1]+wt[i-1];
       printf("%d",wt[i]);
       printf("\nthe turn around time of process %d :",i);
       tat[i]=wt[i]+b[i];
       printf("%d",tat[i]);
   }
}

Output

Round Robin Program Code:

#include<stdio.h>

int main()
{
int i, limit, total = 0, x, counter = 0, time;
int wait_time = 0, turnaround_time = 0, arrival_time = 0, burst_time[10], temp[10];
  
printf("\nEnter Total Number of Processes:\t");
scanf("%d", &limit);
x = limit;
for(i = 0; i < limit; i++)
{
printf("\nEnter Details of Process %d \n", i + 1);
  
printf("Burst Time:\t");
scanf("%d", &burst_time[i]);
temp[i] = burst_time[i];
}
printf("\nEnter Time Slot:\t");
scanf("%d", &time);

for(total = 0, i = 0; x != 0;)
{
if(temp[i] <= time && temp[i] > 0)
{
total = total + temp[i];
temp[i] = 0;
counter = 1;
}
else if(temp[i] > 0)
{
temp[i] = temp[i] - time;
total = total + time;
}
if(temp[i] == 0 && counter == 1)
{
x--;
       printf("Process %d Burst Time %d Turnaround Time %d Waiting Time %d\n",i + 1, burst_time[i], total - arrival_time,        total - arrival_time -    burst_time[i]);
  
       
wait_time = wait_time + total - arrival_time - burst_time[i];
turnaround_time = turnaround_time + total - arrival_time;
counter = 0;
}
if(i == limit - 1)
{
i = 0;
}
else if(arrival_time <= total)
{
i++;
}
else
{
i = 0;
}
}
  
return 0;
}

Output

Priority Program Code:

#include<stdio.h>

int n,i,b[10],temp,temp2,j,wt[10],tat[10],p[10];

void main()
{
   printf("enter no of process");
   scanf("%d",&n);
   for(i=0;i<n;i++)
   {  
       printf("enter burst time of process %d :",i);
       scanf("%d",&b[i]);
       printf("enter priority of process %d :",i);
       scanf("%d",&p[i]);
   }

   for(i=0;i<n;i++)
   {      
       for(j=0;j<n-1;j++)
       {
       if(p[j+1]<p[j])
       {  
           temp=p[j];
          
           p[j]=p[j+1];
          
           p[j+1]=temp;

           temp2=b[j];
           b[j]=b[j+1];
           b[j+1]=temp2;
          
       }
          
   }  
   }
   for(i=0;i<n;i++)
       printf("%d",b[i]);
       printf("\n");
   for(i=0;i<n;i++)
       printf("%d",p[i]);  

   for(i=0;i<n;i++)
   { printf("\nthe waiting time of process %d :",i);
       wt[i]=b[i-1]+wt[i-1];
       printf("%d",wt[i]);
       printf("\nthe turn around time of process %d :",i);
       tat[i]=wt[i]+b[i];
       printf("%d",tat[i]);
   }
}


Output


Related Solutions

Write Algoritm , code and output. In C++ In Operating Systems , Simulate with a program...
Write Algoritm , code and output. In C++ In Operating Systems , Simulate with a program to schedule disk in seek optimization.
After you complete the Practice Tasks, you learn about new developments at Game Technology. Your initial...
After you complete the Practice Tasks, you learn about new developments at Game Technology. Your initial design was good, but the team leader wants you to try another approach. She put these questions to you: "Should corrective maintenance get a higher prioritythan other types of maintenance? Why or why not? Should cost-benefit issues be considered? If so, how would this be done?" Also, your security plan was good, but did not go far enough. The team leader wants you to...
a) Explain how ONE (1) of the COBIT 5 key principles assists in delivering information technology...
a) Explain how ONE (1) of the COBIT 5 key principles assists in delivering information technology governance in an organisation.
Make a list of three tasks using health information systems that would need to be completed...
Make a list of three tasks using health information systems that would need to be completed by a healthcare manager on a daily basis. How would you prioritize them? what is the Reference for this informations?
- Discuss the operating principles of both heat pumps and industrial refrigeration systems. - Assess the...
- Discuss the operating principles of both heat pumps and industrial refrigeration systems. - Assess the factors that influence the economics of heat pumps. - - Discuss the apparent contradiction between refrigeration cycles and the second law. - Conduct a cost-benefit analysis on the installation of a ground source heat pump on a smallholding. Present your findings in the form of academic poster/presentation
Differences Between Linux and Windows Operating Systems Two key differences between a Linux operating system and...
Differences Between Linux and Windows Operating Systems Two key differences between a Linux operating system and a Windows operating system are the concepts of “mounting” and “drive” letters. Provide an example for each. Why is it important to plan disk partitioning before installing Linux? Discuss the advantages of disk partitioning. Also discuss what logical volume management (LVM) is and why or why you might use it.
Discuss at least 4 common tasks of operating systems. Explain how Windows might accomplish one of...
Discuss at least 4 common tasks of operating systems. Explain how Windows might accomplish one of the tasks and how the Mac OS or Linux might accomplish it differently.
What are the key principles of design of an experiment? Hint: what principles do you use...
What are the key principles of design of an experiment? Hint: what principles do you use to control for bias and chance variation etc. Give an illustrative example from real life.
Simulate a problem with undo. You will need to be connected as user SYSTEM or some...
Simulate a problem with undo. You will need to be connected as user SYSTEM or some other user to whom you have granted the DBA role. . Create an undo tablespace with a single datafile of only 200 KB. Do not set the file to autoextend. . Set the database to use this small undo tablespace. Confirm that an undo segment has been created in this tablespace and that it is online by querying the views DBA_ROLLBACK_SEGS and V$ROLLSTAT. Why...
Describe the following key principles and tools for effective financial systems: [80-120 words] a) Transaction Recording...
Describe the following key principles and tools for effective financial systems: [80-120 words] a) Transaction Recording b) Reconciliation Processes c) Invoicing d) Cash Flow Management
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT