OS A191 - Assign 2 Question
OS A191 - Assign 2 Question
Assignment 2
(Individual work)
NAME:
MATRIC NO.:
1
1. Describe the relationship between a process and a thread in a multicore system.
(2 marks)
A processes is a container for threads, which has it' s own memory space. A process
may contain one or more threads, which share that memory space, all of the file
descriptors and other attributes.
The threads are the units of execution within the process, they process a register set,
stack, program counter, and scheduling attributes
a) Cooperating process
Cooperating processes are those that can affect or are affected by other
processes running on the system. Cooperating processes may share data with
each other
b) Independent process
c) Race condition
2
d) Critical section
A Critical Section is a code segment that accesses shared variables and has
to be executed as an atomic action.
e) Semaphore
Semaphores are integer variables that are used to solve the critical section
problem by using two atomic operations, wait and signal that are used for
process synchronization.
3
3. There are many multiprocessing configuration types, one of them is the
master/slave configuration shown in the diagram
- Reliability is no higher than for a single processor system because if master processor
fails, entire system fails.
- Can lead to poor use of resources because if a slave processor becomes free while
master is busy, slave must wait until the master can assign more work to it.
- Increases number of interrupts because all slaves must interrupt master every time
they need OS intervention
4
4. Explain briefly these reasons of process termination: (5 marks)
a. Privileged instruction
The process has waited longer than a specified maximum for a certain event to
occur.
b. Protection error
The process attempts to use a resource or a file that it is not allowed to use, or
it tries to use it in an improper fashion, such as writing to a read-only file
c. Bounds violation
The process tries to access a memory location that it is not allowed to access
d. Arithmetic error
The process tries a prohibited computation, such as division by zero, or tries to
store numbers larger than the hardware can accommodate.
e. Time overrun
The process has waited longer than a specified maximum for a certain event to
occur.
5
5. Explain the key differences between the preemptive and non-preemptive
scheduling. (5 marks)
6. Briefly explain the differences between the following pair of terms related to
process management concept in operating system (4 marks)
6
7. Consider the following workload:
Use time scale diagram as shown below for the FCFS example to show the
schedule for each requested scheduling policy
(12 marks)
a)
P1 P2 P1 P4 P3
0 2 4 7 11 21
B)
P1 P2 P4 P3
0 5 7 11 21
C)
P1 P2 P3 P4 P1 P2 P3 P4 P4
0 3 5 8 11 13 16 17 20 21
7
8. What do we need to guard against the race condition? (2 marks)
To avoid race condition we need Mutual Exclusion. Mutual Exclusion is someway of
making sure that if one process is using a shared variable or file, the other processes
will be excluded from doing the same things.
9. Assume that at time 5 no system resources are being used except for the
processor and memory. Now consider the following events:
At time 5: P1 executes a command to read from disk unit 3.
At time 15: P5’s time slice expires
At time 18: P7 executes a command to write to disk unit 3.
At time 20: P3 executes a command to read from disk unit 2.
At time 24: P5 executes a command to write to disk unit 3.
At time 28: P5 is swapped out.
At time 33: An interrupt occurs from disk unit 2: P3’s read is complete.
At time 36: An interrupt occurs from disk unit 3: P1’s read is complete.
At time 38: P8 terminates.
At time 40: An interrupt occurs from disk unit 3: P5’s write is complete.
At time 44: P5 is swapped back in.
At time 48: An interrupt occurs from disk unit 3: P7’s write is complete.
For each time 22, 37, and 47, identify which state each process is in. if a process
is blocked, further identify the event on which is it blocked
(15 marks)
Time 22:
P1 is in Blocked state - Blocked for I/O
P3 is in Blocked state - Blocked for I/O
P5 is in Running state on unit 3
P7 is in Blocked state - Blocked for I/O
P8 is in Running state on unit 1
Time 37:
P1 is in Running state on unit 3
P3 is in Running state on unit 2
P5 is in Blocked or Suspended state due to an interrupt by P1
P7 is in Blocked for I/O
P8 is in Running state on unit 1
Time 47:
8
P1 is in Running state on unit 3
P3 is in Running state on unit 2
P5 is in Ready state
P7 is in Blocked for I/O
P8 is in Exit state
Show the order that a processor would follow to calculate G. To do so, break
down the equation into the correct order of operations, with one calculation per
step. Show the formula for each step, assigning new letters to calculations as
necessary. (7 marks)
1. T1 = C2
2. T2 = A+T1
3. T3 = E - 1
4. T4 = T33
5. T5 = T4/D
6. T6 = T2*T5
7. G =T6+B
9
11. Consider the following snapshot of a system:
c) If a request from process P1 arrives for (0,4,2,0), can the request be granted
immediately?
1520 – 0420 = 1100
The value of available being 1100.the ordering of process that can finish is
P0, P2, P3, P1, P4.
10
12. A system has three processes (P1, P2, P3) and three reusable resources (R1, R2,
R3). There is one instance of R1, two instances of R2 and three instances of R3.
P1 holds an R1 and an R3 and is requesting an R2. P2 holds an R3 and is
requesting an R1 and an R2. P3 holds two R2 and an R3 and is requesting an R1.
(9 marks)
a. Draw the resource allocation graph for this situation.
R1 R2 R3
P1 P2 P3
11