0% found this document useful (0 votes)
183 views11 pages

OS A191 - Assign 2 Question

At time 5: P1 executes a read from disk 3. At time 15: P5's time slice expires. At time 18: P7 executes a write to disk 3. At time 20: P3 executes a read from disk 2. At time 24: P5 executes a write to disk 3. At time 28: P5 is swapped out.

Uploaded by

HooiSzeHee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
183 views11 pages

OS A191 - Assign 2 Question

At time 5: P1 executes a read from disk 3. At time 15: P5's time slice expires. At time 18: P7 executes a write to disk 3. At time 20: P3 executes a read from disk 2. At time 24: P5 executes a write to disk 3. At time 28: P5 is swapped out.

Uploaded by

HooiSzeHee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

STIK2044: Operating System

Assignment 2
(Individual work)

NAME:

MATRIC NO.:

RULES AND INSTRUCTIONS

• Answer concisely! Write clearly!

• Use Microsoft Word in answering the assignment.

• Submission should be made in two methods; Hardcopy and softcopy online.

• Submission due date on 21 November 2019

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 

2. Define the following: (5 marks)

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

Occasions when several processes work directly together to complete a


common task.

b) Independent process

Independent Processes operating concurrently on a systems are those that can


neither affect other processes or be affected by other processes

c) Race condition

A race condition is an undesirable situation that occurs when a device or


system attempts to perform two or more operations at the same time, but
because of the nature of the device or system, the operations must be done
in the proper sequence to be done correctly.

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

Discuss THREE (3) disadvantages of using this master/slave configuration


(3 marks)

- 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)

Preemptive scheduling Non-preemptive scheduling


The resources are allocated to a process Once resources are allocated to a process,
for a limited time. the process holds it till it completes its
burst time or switches to waiting state.
Process can be interrupted in between. Process cannot be interrupted till it
terminates or switches to waiting state.
Preemptive scheduling is flexible. Non-preemptive scheduling is rigid.
Waiting time and Response time is Waiting time and Response time is
less. more.
Preemptive scheduling has overheads of Non-preemptive scheduling does not
scheduling the processes.. have overheads.

6. Briefly explain the differences between the following pair of terms related to
process management concept in operating system (4 marks)

a. Turnaround time and response time


Turnaround refers to the time a given process takes from submission to
completion.
Response time is the time difference between the issuance of a command and
the start of a response to that command.

b. shortest-process-next and shortest-remaining-time scheduling


shortest-process-next - Shortest remaining time is optimal and it mostly gives
minimum average waiting time for a given set of CPU bursts of the processes.

shortest-remaining-time scheduling - is a scheduling method that is a pre-


emptive version, processor allocated to job closet to completion

6
7. Consider the following workload:

Process Burst time Priority Arrival Time


P1 50 ms 4 0 ms
P2 20 ms 1 20 ms
P3 100 ms 3 40 ms
P4 40 ms 2 60 ms

Show the schedule using:


a. Shortest remaining time
b. Nonpreemptive priority (a smaller priority number implies higher priority)
c. Round robin with quantum 30 ms.

Use time scale diagram as shown below for the FCFS example to show the
schedule for each requested scheduling policy

Example for FCFS (1 unit = 10 ms)


P1 P1 P1 P1 P1 P2 P2 P3 P3 P3 P3 P3 P3 P3 P3 P3 P3 P4 P4 P P4
4
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

(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.

No assumptions may be made about speeds or the number of CPUs

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

10. Consider this formula:


G = (A + C2)*(E-1)3/D + B

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:

Allocation Max Available


ABCD ABCD ABCD
P0 0012 0012 1520
P1 1000 1750
P2 1354 2356
P3 0632 0652
P4 0014 0656

Answer the following questions using the banker’s algorithm: (9 marks)

a) What is the content of the matrix Need?


Max –allocation
P0 – 0000
P1 - 0750
P2 – 1002
P3 – 0020
P4 – 0642

b) Is the system in a safe state?


Yes. It is because the available is 1520, process P0 or P3 can run, then will
releases its resources when process P3 runs, which allow all other existing processes
to run

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

a. Write all the cycle(s) in the graph.

Cycle 1 = P3 R1  P1  R2 P3

b. Does a deadlock exist? Why?


Yes, a deadlock does exist.
It is because P3 is waiting for an instance of R1, the only instance of which is held
by P1 and P1 is waiting for an instance of R2, both instances of which are held by P3

11

You might also like