Operating Systems (H)

1.

Consider two threads T1 and T2 which execute the following code concurrently, accessing shared variables a, b, and c:

Initialization

int a = 4;
int b = 0;
int c = 0;

Thread 1

if (a < 0) { c = b - a; } else { c = b + a; }

Thread 2

b = 10; a = -3;

What are the possible values for variable c after both threads complete? Assume that reads and writes of the variables are atomic

2. The time interval between the time of submission and completion of the job is called:

3. A program in execution is called:

4. CPU burst time indicates the time, the process needs the CPU. Consider the following processes with their respective CPU burst times (in milliseconds). Process P1 with CPU burst time 10ms, Process P2 with CPU burst time 5 ms, and Process P3 with CPU burst time 5 ms. Based on a FCFS scheduling scheme, if the processes arrived in the order: P1, P2, P3 at time t=0, which is the average waiting time?

5.

Consider the following system snapshot using data structures in the Banker’s algorithm, with resources A, B, C, and D, and process P0 to P4:

Using the Banker’s algorithm:

How many resources of type A, B, C, and D are there?

6.

Consider the following system snapshot using data structures in the Banker’s algorithm, with resources A, B, C, and D, and process P0 to P4:

Using the Banker’s algorithm:

If a request from process P4 arrives for additional resources of (1,1,0,0) can the Banker’s algorithm grant the request immediately?

7.

Consider the following system snapshot using data structures in the Banker’s algorithm, with resources A, B, C, and D, and process P0 to P4:

Using the Banker’s algorithm:

Which is the sequence of the processes to get the system in a safe state?

8. Consider the following resource allocation graph:

Is the system in a deadlock state?

9.

We need to use semaphores to synchronize processes A, B, C, and D so that A completes before any other process (B, C, or D) starts, and B completes before C or D may execute, but C and D may execute concurrently.

Which of the following statements implement the above-mentioned requirement?

10.

Suppose that a process executes the following code:

/*initialization section*/ semaphore S_a = 0; semaphore S_b = 0; /*logic section*/ acquire(S_a); - access resource R_a release(S_a); acquire(S_b); - access resource R_b release (S_b);

Assume that the system has one resource of type R_a and one resource of type R_b. How would you change the code so that it provides mutually exclusive access to R_a and R_b?