Solved-Operating Systems:- Assignment 2- Solution

$30.00 $19.00

Notes: This is an individual assignment. No late assignment will be accepted. Please sub-mit your answers through blackboard. This assignment is worth 10% of your total grade. Corresponding TA: Aditya Sasongko (msasongko17@ku.edu.tr) Problem 1 (20 points) Consider the following set of processes, with the length of the CPU-burst time given in milliseconds: Process Burst Time…

You’ll get a: . zip file solution

 

 

Description

5/5 – (2 votes)

Notes: This is an individual assignment. No late assignment will be accepted. Please sub-mit your answers through blackboard. This assignment is worth 10% of your total grade.

Corresponding TA: Aditya Sasongko (msasongko17@ku.edu.tr)

Problem 1

(20 points) Consider the following set of processes, with the length of the CPU-burst time given in milliseconds:

Process

Burst Time

Priority

P1

8

3

P2

5

1

P3

3

3

P4

1

4

P5

10

2

The processes are assumed to have arrived in the order P1, P2, P3, P4, P5, all at time 0.

  1. Draw four Gantt charts illustrating the execution of these processes using FCFS, SJF, a non- preemptive priority (a smaller priority number implies a higher priority), and RR (quantum = 4 ms) scheduling.

  1. Calculate the waiting time of each process for each of the scheduling algorithms in part

(a). Which of the schedules results in the minimal average waiting time?

  1. Calculate average turnaround time for each of the scheduling algorithms in part (a). Assume no context-switch overhead.

Problem 2

(10 points) Now assume that the context-switching overhead is equivalent to 0.5 ms. Calcu-late the CPU utilization for all four scheduling algorithms in Problem 1.

1

Student Name:

Page 2 of 3

Problem 3

(15 points) Consider the code example above that creates threads for opening connections at a server.

a) Identify the race condition(s) in the provided program.

b) If you have identi ed any race conditions, use pthread locks to prevent the race condi-tion(s). Provide the code snippet.

c) Could we replace the integer variable available connections with atomic integer, which allows atomic update of a variable of this type? Explain your answer.

atomic t available connections = MAX CONNECTIONS;

Problem 4

(15 points) A hotel management would like to use online reservation system for their rooms. The hotel has M rooms available for online reservation. If all the rooms are occupied, the hotel will not accept any more customers until a room becomes available again (a party leaves the hotel).

Give an algorithm for the hotel using semaphore primitives to limit the number of reserved rooms so that it does not exceed M. Note that a room can accommodate up to 4 customers. If a party more than 4 customers arrives, multiple rooms may be needed. If the required number of rooms is not available, the room request for the entire party will be declined. Provide a pseudo-code and brie y explain your algorithm in a short paragraph.

21

22 }

20

17 /* When a thread wishes to drop a connection with the server, 18 it invokes disconnect() */

19 int disconnect() { available_connections ++; return 0;

13

14

15 }

16

else

available_connections –; return 0;

11

12

10

9 int connect() {

i f (available_connections < 1) return -1;

2

3 #define MAX_CONNECTIONS 5000

4 int available_connections = MAX_CONNECTIONS;

5

6 /* When a thread wishes to establish a connection with the server, 7 it invokes the connect() function:*/

8

1

//PROBLEM 3

PROBLEM 4

COMP 304- Operating Systems ( Spring 2020): Assignment 2

COMP 304- Operating Systems ( Spring 2020): Assignment 2 PROBLEM 6

Problem 5

(25 points) Consider a hospital that o ers a free check-up service to senior people (65 years old or older) on Sundays. M many senior citizens (n1; n2; :::; nm) are expected to visit the hospital for this Sunday. Write a monitor (in pseudocode) that allocates 4 equally profes-sional doctors to these people, using the priority numbers of patients for deciding the order of their doctor visit. The older the person, the higher her/his priority is.

When a patient arrives to the hospital, s/he should call void request doctor(int priority) function. If all doctors are busy, the patient is made to wait. When a patient is done with her/his visit, the patient should call release doctor() function. You can assume that there is a sort() function, which takes an integer array and sorts it.

Problem 6

(15 points) Consider the following snapshot of a system, where A, B, C and D are resources and P1-P5 are processes.

Allocation

Max

Available

ABCD ABCD ABCD

P1

0014

0656

1520

P2

0632

0652

P3

1354

2356

P4

0012

0012

P5

1000

1750

Using the bankers algorithm for deadlock avoidance:

  1. What is the content of the matrix Need?

  1. Is the system in a safe state? Explain your answer.

  1. If a request from process P5 requests (0, 3, 3, 0), can the request be granted immediately? Explain the reason.

Student Name: Page 3 of 3