Things you should know:This assignment contributes 30% towards overall of your course marks.
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.programming代写
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 bit “challenged” with programming due to their major’s 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.
Objective: The objective of this task is to develop basic shell scripting skills with parameter handling.
You are required to write a shell program/script 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 usageg.,
“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
c.Program should correctly concatenate data of the two files and save it into a new file named output.txt and generates a success
Assumption: Consider the input files are in the same directory as that of your concatenatefile.sh.
Objective: The objective of this task is to develop a better understanding of multithreading.
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:
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.
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 C/C++ 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, leteach 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.
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() function/method 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 |
Run your program using the following values to test your program. Copy your result and paste it in the readme.txt file under the heading “Test Run Results”.
int customerNo = 5;
int resourceNo = 3;
//how many resources are already allocated to each customer
int[][] reserved = new int[customerNo][resourceNo];
//maximum how many resources each customer can request for
int[][] max = new int[customerNo][resourceNo];
//currently available resources
int[] available = new int[resourceNo]; //set availability of all resources to 20
Objective: The objective of this task is to develop a better understanding of process synchronization and deadlock handling.
Traffic light problem is a classical example of synchronization and deadlock handling. We have discussed during our lecture (Week-5) 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:
Tasks | Criteria | Allocated Marks |
General | a. Comments and readme file | 5 |
b. Quality of code (Whitespace, Naming, Reuse, Modularity, Encapsulation) | 5 | |
Sub-Total | 10 | |
Task-1 | a. Welcome message | 2 |
b. Getting input | 2 | |
c. Displaying error message on wrong input | 2 | |
d. Correct generation of the output.txt file | 4 | |
Sub-Total (Task-1) | 10 | |
Task-2 | a. Main function/method | 4 |
b. requestResource function | 6 | |
c. releaseResource function | 4 | |
d. Rule function | 4 | |
e. Use of multithreading | 2 | |
f. Thread run function | 5 | |
g. Running and output | 5 | |
Sub-Total (Task-2) | 30 | |
Task-3 | a. Main function | 4 |
b. Taking appropriate input | 2 | |
c. Deadlock and Synchronization handling | 10 | |
d. Time of traffic flow and again asking for input | 4 | |
Sub-Total (Task-3) | 20 |