CS604 Assignment 3 Solution and Discussion

Operating Systems (CS604)
Assignment # 03
FALL 2019
Total marks = 20

Deadline Date
22nd Jan 2020

Please carefully read the following instructions before attempting assignment.

RULES FOR MARKING
It should be clear that your assignment would not get any credit if:
 The assignment is submitted after the due date.
 The submitted assignment file does not open or it is corrupt.
 The submitted assignment solution is copied from any other student or from the internet.

You should consult the recommended books to clarify your concepts as handouts are not sufficient.

You are supposed to submit your assignment in .doc or docx format.
Any other formats like scan images, PDF, zip, rar, ppt and bmp etc. will not be accepted.

Objective:
• The objective of this assignment is to provide understanding of:
Semaphore and Resource Allocation Graph

NOTE

No assignment will be accepted after the due date via email in any case (whether it is the case of load shedding or internet malfunctioning etc.). Hence refrain from uploading assignment in the last hour of deadline. It is recommended to upload solution file at least two days before its closing date.

If you find any mistake or confusion in assignment (Question statement), please consult with your instructor before the deadline. After the deadline no queries will be entertained in this regard.

For any query, feel free to email at:
[email protected]

Question No 01 8 Marks

Consider a banking transaction system where two processes Cash Withdrawal and Cash Deposit for a bank account could take place at the same time. The Cash Withdrawal process helps in withdrawing some cash amount using the ATM and the Cash Deposit process is used to deposit some amount into the account through a cheque. Which synchronization technique should be adopted in order to make sure that these processes can take place mutually exclusive? Write pseudo-code or algorithm for these two processes.

Note: No need to write code in any programing language.

Question No 02 12 Marks

Suppose a computer lab comprises of two printers, three scanners, and four ROM writers. There are three programs currently running on some computer. Assume program P1 is currently allocated a printer and two ROM writers and it is waiting for a scanner. Program P2 is allocated a scanner and it is waiting for a printer. Program P3 is allocated two ROM writers, a scanner, and a printer. Draw the corresponding resource allocation graph for these three programs. Also specify if the system is in a deadlocked state or not?

Wish you very Best of Luck!

@zareen said in CS604 Assignment 3 Solution and Discussion:

Question No 02 12 Marks
Suppose a computer lab comprises of two printers, three scanners, and four ROM writers. There are three programs currently running on some computer. Assume program P1 is currently allocated a printer and two ROM writers and it is waiting for a scanner. Program P2 is allocated a scanner and it is waiting for a printer. Program P3 is allocated two ROM writers, a scanner, and a printer. Draw the corresponding resource allocation graph for these three programs. Also specify if the system is in a deadlocked state or not?

6b44c7a6-62dc-4070-a9b2-efc2d178cf0a-image.png

The system is not in deadlock state as it is clear from the above graph it is multi instance and circular weight.

@zareen said in CS604 Assignment 3 Solution and Discussion:

Question No 01 8 Marks
Consider a banking transaction system where two processes Cash Withdrawal and Cash Deposit for a bank account could take place at the same time. The Cash Withdrawal process helps in withdrawing some cash amount using the ATM and the Cash Deposit process is used to deposit some amount into the account through a cheque. Which synchronization technique should be adopted in order to make sure that these processes can take place mutually exclusive? Write pseudo-code or algorithm for these two processes.
Note: No need to write code in any programing language.

Solution Idea:


The codes for reader and writer processes are shown below:

Semaphore mutex, cash;
int transaction;
transaction=0;
mutex=1;

cash=1;
wait(mutex);
transaction++;

if (transction == 1)

wait(cash);
signal(mutex);
cash=cash+1
...
Cash deposit process is performed
...

wait(mutex);
transaction--;
if(transaction == 0)
signal(cash);
signal(mutex);


wait(cash);
cash=cash-1;
...
Cash Withdraw is performed

...
signal(cash);