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

  • I need this done ASAP. Please write a bash shell script that does the following: Prints...

    I need this done ASAP. Please write a bash shell script that does the following: Prints out how many users are logged on. This can be accomplished using who and wc. Prints out a list of currently logged on users. This can be accomplished using who, grep, regular expressions, and echo. Prints out how many processes you have running from past days, and a list of those jobs. Use `whoami` to get your username. Run ps -ef and see how...

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

  • 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")...

  • #A common problem in academic settings is plagiarism #detection. Fortunately, software can make t...

    #A common problem in academic settings is plagiarism #detection. Fortunately, software can make this pretty easy! # #In this problem, you'll be given two files with text in #them. Write a function called check_plagiarism with two #parameters, each representing a filename. The function #should find if there are any instances of 5 or more #consecutive words appearing in both files. If there are, #return the longest such string of words (in terms of number #of words, not length of the...

  • Please write the following code as simple as possible in python: You will need to define...

    Please write the following code as simple as possible in python: You will need to define a function with four arguments. Here is what I used: > def find_matches(file1.txt, output1.txt, strings, value): file1.txt will contain a list of various strings. The program must copy from the first argument, and it should be written in the second argument (the second file, "output1.txt"). The third and fourth arguments will determine which specific strings will be copied over to the second file. For...

  • using java File Details – Build a class called FileDetails.java. When you instantiate this class and...

    using java File Details – Build a class called FileDetails.java. When you instantiate this class and give it a filename, it will report back the size of the file, whether the file is Readable and whether the file is Writeable; plus any other file information that you might deem important. This cd goes in main FileDetails fd=newFileDetails(“anyfile.doc”); All other code goes in the constructor. Write a String to a File using PrintStream – This time build a class WriteString. This...

  • C++ programming help. The only change you have to make is in current program, where it...

    C++ programming help. The only change you have to make is in current program, where it says "your code goes here", do not make any changes to any other files, they are just there to show you. This code should be written for arbitrary data, not specifically for this sequence of data. The only place you need to write a code is marked YOUR CODE GOES HERE. You have been supplied a file with data in it (data2.txt). The line...

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

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
ADVERTISEMENT