COMP604: Operating Systems
Semester 2, 2019
Assignment
Due Date: 04Oct2019 till 5:00pm
Things you should know:
This assignment contributes 30 towards overall of your course marks. In this assignment you will be asked to implement some of the concepts and skills you have learned in this course. You may be required to do some research as well but, please be aware of AUT s plagiarism and cheating policies.
Late submission penalty is applied with a 5 deduction per day. If you submit the assignment more than 5 days late, then you will be awarded 0 marks.
This is a team or individual assignment: The assignment is intended to be a team assignment for teams of two. However, if you feel it inconvenient to do this as a team, you are free to choose to submit an individually worked assignment. For those who feel a bitchallengedwith programming due to their majors nature, this is a chance to team up with somebody more comfortable with programming.
This assignment consists of three tasks and all tasks are mandatory.
Task1: Shell scripting
Objective: The objective of this task is to develop basic shell scripting skills with parameter handling.
You are required to write a shell programscript to concatenate data from two files. Your program should perform the following:
a. Your script should start executing by greeting the user and displaying the information about its usage e.g.,
Welcome user username.
This is .concatenatefile.sh script file. You are required to enter names of two text files and the program will concatenate those files and generate an output.txt file .
b. Check the no. of parameters passed by the user. If the user inputs incorrect no. of parameters or the files name entered does not exist; your program should display the error message and terminate.
c. Program should correctly concatenate data of the two files and save it into a new file named output.txt and generates a success message.
Assumption: Consider the input files are in the same directory as that of your concatenatefile.sh.
1
Task2: Banker s Algorithm 1
Objective: The objective of this task is to develop a better understanding of
multithreading.
Overview:
Banker s Algorithm is used by many Operating Systems to avoid deadlock and handle resource allocation properly. This algorithm works based on the following three factors:
1. What is the maximum no. of requests each process can make for each resource?
2. Howmucheachresourceiscurrentlyallocatedtoeachprocess?
3. Howmucheachresourceiscurrentlyavailablefreeforusewiththeoperating
system?
Rule
Resource will be allocated to the requested process if and only if the no. of
resources requested are currently available free for use with the operating system.
System Implementation:
As, all the customers will be sharing the available resources yet having the record of their individual allocated resources, we can use Threads to implement this problem. We are going to implement Banker s Algorithm using JAVA Thread Class you can use JAVA Runnable or PThreads in CC if you desire.
We will be maintaining the record of total available resources of each type with the system, the number of each type of resources occupied by each customer. Method requestResource will be used to assign the requested resources to the relevant customer IF the Rule explained in the above section permits. With each served request a thread will be created and start functioning. For the assignment purpose, let each thread sleep for some random time before exiting. On exiting, thread will release the resource it was occupying.
Another method releaseResource will be used to release a resource. Once the resource is released, it will be returned to the pool of available resources. The method should also print the current status of the overall system resources.
The following program structure and steps may be helpful in completing this task.
Main function
Initialize available resources
Randomly select a customer and generate its request
Call the requestResource function
requestResource
Call the rule function to check if the request meets the rule criteria
IF rule function returns success
o Assign requested resources to the customer
2
o Create and start thread corresponding to each resource assigned to the customer
IF rule function returns failure
o Display appropriate message for the customer and advice to wait till
the requested resources are available
rule
Check the rule criteria for the requested no. of resources
Return true or false accordingly
releaseResource
Takes the resource from the customer and put it in the currently available
resources to be used by other customers on request
Print the status of the currently available resources
run functionmethod in the class that extends Thread class
Should be called when each Thread starts
Let each thread sleep for some random sleep time
When awake, call the releaseResource function
exit
Test Run:
Run your program using the following values to test your program. Copy your result and paste it in the readme.txt file under the headingTest Run Results .
int customerNo5; int resourceNo3;
how many resources are already allocated to each customer int reservednew intcustomerNoresourceNo;
maximum how many resources each customer can request for int maxnew intcustomerNoresourceNo;
currently available resources
int availablenew intresourceNo; set availability of all resources to 20
References:
1 https:en.wikipedia.orgwikiBanker27salgorithm
3
Task3: Traffic Light Problem
Objective: The objective of this task is to develop a better understanding of process synchronization and deadlock handling.
Overview:
Traffic light problem is a classical example of synchronization and deadlock handling. We have discussed during our lecture Week5 a Petri Nets model for handling this problem. The Petri Nets model is also given below for your reference:
Fig.1. Petri Nets for Traffic Light
You are required to write a JAVA or C code to implement this Petri Nets model.
Clearly mention in your code using comments the piece of code you have written to address the synchronization and deadlock handling.
Your program should be able to:
a. Asktheuserwhichtrafficlightitwantstobegreen.
b. Allow that traffic flow for a fixed time of 5 seconds and then stops both traffic flows and repeat a part.
4
Submission Guidelines:
You are required to submit a single zip file containing three folders one for each task on Blackboard before the due date and time.
Please make sure that you have added areadme.txtfile for both the tasks, mentioning the following:
State if it s a team or individual work. If it s a teamwork, please give the name and student number of your team members.
A list of all the files in the directory
A brief instruction on how to compile and run the programs
Your answer to Test Run for Task2.
Marking Guide:
Tasks
Criteria
Allocated Marks
General
a. Commentsandreadmefile
5
b. Quality of code Whitespace, Naming, Reuse, Modularity, Encapsulation
5
SubTotal
10
Task1
a. Welcomemessage
2
b. Gettinginput
2
c. Displaying error message on wrong input
2
d. Correctgenerationoftheoutput.txtfile
4
SubTotal Task1
10
Task2
a. Mainfunctionmethod
4
b. requestResourcefunction
6
c. releaseResource function
4
d. Rulefunction
4
e. Useofmultithreading
2
f. Thread run function
5
g. Runningandoutput
5
SubTotal Task2
30
Task3
a. Mainfunction
4
b. Taking appropriate input
2
c. Deadlock and Synchronization handling
10
d. Time of traffic flow and again asking for input
4
SubTotal Task3
20
TOTAL
70
5
Reviews
There are no reviews yet.