Question

Question I This question carries 20% of the marks for this assignment. You are asked to...

Question I

This question carries 20% of the marks for this assignment.

You are asked to develop a set of bash shell script:

  1. Write a script that asks for the user's salary per month. If it is less or equals to 800, print a message saying that you need to get another job to increase your income, what you earn is the Minim living cost. If the user's salary is higher than 800 and below 2000, print a message telling the user that your income is just right to cover your expenses. [10 marks]
  2. Write a script that takes exactly one argument, a file name. If the number of arguments is more or less than one, print a usage message. If the argument is not a file name, print another message. For the given file, print on the screen its content. [5 marks]
  3. Write a script that does the following [5 marks]
  • Display the name of the script being executed.
  • Display the second, third and fifth argument given to the script.
  • Display the total number of arguments passed to the script.
  • Print all the values of the remaining arguments.
  • Print the number of arguments

Question II

This question carries 50% of the marks for this assignment.

This question is about avoiding race condition by using synchronization mechanism provided by the JAVA programming language. We provided you with a Netbeans JAVA project. The project idea is as follows: we want to merge the content of four files into a single file, as follows. Below is the content of all four files:

F1 content: 1 1 1 1

F2 content: 2 2 2 2

F3 content: 3 3 3 3

F4 content: 4 4 4 4

After merging them into the Sink file, we expect the following content in the sink file:1234123412341234

We want to read from each file only one integer value at a time (starting form file number 1, number 2 and so on) and write theses integers values ( in the same order we read them) into a specific sink file, we want to repeat it until all file files are empty.

Please note that all files have the same number of integers.

We have provided you with a template project that needs to be modified to accomplish the above task correctly.

The project is composed of the following classes including four text files:

Four text files called “f1.txt”, “f2.txt”, “f3.txt” and “f4.txt”, each file has a sequence of integer corresponding its name, for instance “f2.txt” contains a sequence of integers all are 2.

The following JAVA source code files are included in the NetBeans projects:

WriteToFile: A helper class to write into a file.

SyncWriteToFile: which control the access to the file, it does so by aggregating an object of the class “WriteToFile”

MergeFiles that extends Thread: it is intended to read all integers form a specific file and use an object of “SyncWriteToFile” to write them into the sink file at the appropriate place.

TMA_Tm298_SummerEgJo: contains the main method to test the program

Read the source code of the above classes carefully and run the project. You will discover that the content of the sink file is not as expected and each time you run it you got a different content. Provide screen shots form running the project without any modification. Provide convincing justification, why you got these results. [15 marks]

In order to get the expected sink file content, you need to modify the project as follows:

You can do so by first identifying the shared resources and then the critical section code in the project. [10 marks]. Then you need to change the critical section code so that the sink file contains the following result no matter how many times you run the project. The sink file correct content is :1234123412341234. [25 marks]

You are sked to submit the whole project (as one zip file) after all modification.

Question III

This question carries 30% of the marks for this assignment.

There are four processes P1, P2, P3 and P4 that will be executed by a scheduler on a concurrent system using different scheduling policy. Their arrival times and service times are shown in the following table. Complete the table using the listed three scheduling policy, draw the Gantt chart (assuming that the quantum time is 2 second for preemptive scheduling algorithm) and calculate the average waiting time [10 marks]:

  1. When a FIFO scheduling policy is used.
  2. When SJF (non-preemptive) scheduling policy is used.
  3. When RR scheduling policy is used.

Process ID

Arrival time in second

Service time

Finish time

Turnaround

Waiting time

Normalized turnaround

P1

0

3

?

?

?

?

P2

1

5

?

?

?

?

P3

4

2

?

?

?

?

P4

2

4

?

?

?

?

ues this code

package tma_tm298_summer.egjo;

import java.io.FileNotFoundException;

/**
*
* @author macbook
*/
public class TMA_Tm298_SummerEgJo {

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException, InterruptedException {
// TODO code application logic here
SyncWriteToFile outToFile= new SyncWriteToFile("sinkFile.txt");
MergeFiles file1= new MergeFiles(1, "f1.txt", outToFile);
MergeFiles file2= new MergeFiles(2, "f2.txt", outToFile);
MergeFiles file3= new MergeFiles(3, "f3.txt", outToFile);
MergeFiles file4= new MergeFiles(4, "f4.txt", outToFile);
System.out.println("file merging started");
file1.start();
file2.start();
file3.start();
file4.start();
// let main wait until all data merged
file4.join();
System.out.println("file merging ended succesfully");
}
  
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

question 1)

2)

3)

Add a comment
Know the answer?
Add Answer to:
Question I This question carries 20% of the marks for this assignment. You are asked to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question II This question carries 50% of the marks for this assignment. This question is about...

    Question II This question carries 50% of the marks for this assignment. This question is about avoiding race condition by using synchronization mechanism provided by the JAVA programming language. We provided you with a Netbeans JAVA project. The project idea is as follows: we want to merge the content of four files into a single file, as follows. Below is the content of all four files: F1 content: 1 1 1 1 F2 content: 2 2 2 2 F3 content:...

  • Question III This question carries 20% of the marks for this assignment. Given the following mix...

    Question III This question carries 20% of the marks for this assignment. Given the following mix of tasks, task lengths and arrival times, compute the completion [5 marks and response time time from the arrival to the finish time) (5 marks for each task, along with the average response time for the FIFO. RR and SJF algorithms. Assume a time slice of 10 milliseconds and that all times are in milliseconds. You are kindly asked to provide the Gantt Chart...

  • use python IDEL Please highlight the answer Problem 3 Files. Read the following code and answer...

    use python IDEL Please highlight the answer Problem 3 Files. Read the following code and answer the next five questions about it. The contents of the files list 1.txt and list2.txt are the following (given side by side): list 1. txt content: list2.txt content 2 apples 2 apples 3 oranges 1 loaf of bread 2 eggs 2 eggs 1 cereal box # the program code starts here filename1 = "list 1.txt" filename2 - "list2.txt" filename3 - "listdiff.txt" with open (filename1,"r")...

  • Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The progra...

    Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs opening any of the 3 For example, (user input shown in caps in first line) Enter first...

  • Experiment with the terminal and C programming   I want you to be able to setup a...

    Experiment with the terminal and C programming   I want you to be able to setup a folder, change to a folder, create a new file with the editor (windows version is fine), rename files, delete files, and change permissions. How to create a compiled program Create your source code; lets say it is named test.c Compile it using: gcc test.c –o test Change the permissions to execute for everyone (755) Run it by: ./test Create two programs The first one...

  • i need help with this scripting assignment in power shell thanks Lab 7: PowerShell Search and...

    i need help with this scripting assignment in power shell thanks Lab 7: PowerShell Search and Report Search Report host path date Execution time nnn Directories n, nnn, nnn Files nnnnnnn Sym links nnnnnnn Old files nnnnnnn Large files nnnn, nnn Graphics files nnnnnnn Executable files nnnnnnn Temporary files n, nnn, nnn TotalFileSize nnnn, nnn Introduction Lab 7 is nearly identical to Lab 2, except it is written in PowerShell, uses no UNIX/Linux tools to do its work, creates no...

  • Could I get some help with this assignment In this assignment, you'll write a program which...

    Could I get some help with this assignment In this assignment, you'll write a program which reads a text file, and prints a histogram of its word sizes. So, for example, the historgram should show the number of words of length 1, of length 2, etc., up to the number of words of length n, where n is some constant defined in your program. To obtain text files that are suitably long, you could try Project Gutenberg, a site containing...

  • UNIX QUESTION Exercise #1. [8 Marks] Create a script that does the following: a. Takes 4...

    UNIX QUESTION Exercise #1. [8 Marks] Create a script that does the following: a. Takes 4 input parameters b. Using the shell special variables print the following: i. The command you executed ii. First input iii. Second input iv. Third input v. Fourth Input vi. Process Id vii. Total number of input parameters [ by querying the system for it ] Exercise #2. [8 Marks] Creates a script that does the following: a. Takes two input parameters b. Using the...

  • Description In this homework, you are asked to implement a multithreaded program that will allow ...

    Description In this homework, you are asked to implement a multithreaded program that will allow us to measure the performance (i.e, CPU utilization, Throughput, Turnaround time, and Waiting time in Ready Queue) of the four basic CPU scheduling algorithms (namely, FIFO, SJE PR, and RR). Your program will be emulating/simulating the processes whose priority, sequence of CPU burst time(ms) and I'O burst time(ms) will be given in an input file. Assume that all scheduling algorithms except RR will be non-preemptive,...

  • C++ For this assignment you will be building on the Original Fraction class you began last...

    C++ For this assignment you will be building on the Original Fraction class you began last week. You'll be making four major changes to the class. [15 points] Delete your set() function. Add two constructors, a default constructor that assigns the value 0 to the Fraction, and a constructor that takes two parameters. The first parameter will represent the initial numerator of the Fraction, and the second parameter will represent the initial denominator of the Fraction. Since Fractions cannot have...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT