Question

In: Computer Science

1. Try running the deadlock simulator using the following command: java deadlock a 2 2 Explain...

1. Try running the deadlock simulator using the following command: java deadlock a 2 2 Explain why a deadlock does not occur.

2. There are two additional process command files ("b0.dat" and "b1.dat") in the distribution. Run the deadlock simulator with this command: java deadlock b 2 1 1 What happens?

Now try this: java deadlock b 2 1 2 Why does the first command result in a deadlock but the second does not? Explain your answer in terms of what is going on in the process command files, b0.dat and b1.dat.

CAN SOMEBODY EXPLAIN THE QUESTIONS.

Solutions

Expert Solution

Assume this is with the MOSS deadlock simulator.
QUESTION 1:
The first command is java deadlock a 2 2
As per the documentation, 'a' represents the prefix for the command files; so a0.dat and a1.dat will be chosen because they have the prefix 'a'.
The next parameter is the number of processes to be created, which is 2 in this case
The third (and any parameters after that) represent the number of instances to create for each resource. In this case, 2 instances will be created for a single resource since there is only one resource parameter.

For a deadlock to happen, there need to be a minimum of 2 resources, so for example, the following steps occuring simultaneously causes a deadlock:
Process 1 requests resource 1 and gets it                       Process 2 requests resource 2 and gets it
Process 1 requests resource 2 but it is locked by process 2       Process 1 requests resource 1 but it is locked by process 2

Since there is only one resource here, no deadlocks can happen.

QUESTION 2:
This time, the command is java deadlock b 2 1 1
This means that command files with the prefix 'b' will be used, specifically, b0.dat and b1.dat. The next parameter indicates that 2 processes will be running simultaneously. Finally, the last two 1's on the command line mean that 1 instance of the first type of resource and 1 instance of the second type of resource will be available.
This configuration can cause a deadlock (depending on commands in b0.dat and b1.dat, which you will have to look into). Each of the two processes can hold a lock on one of the resources (remember there is only one instance of each resource, so only one process can get a usable instance of a resource). And if the two processes now try to lock the resource that the other one has, a deadlock will result.

The next command is: java deadlock b 2 1 2
This creates two processes using the command files starting with 'b'; there are two processes; there is 1 instance of the first resource and 2 instances of the second resource. In this case, suppose one process has locked the first resource (of which there is only one instance). If the second process also wants the first resource, it ends up blocked (waiting). If both processes need the second resource, it is not a problem, since there are 2 instances of the second resource. Hence, the first process (which has successfully locked the first process) will never be blocked and will eventually complete its work and unlock the first resource. Hence, we never have a situation with two processes both being blocked, waiting for each other. Hence a deadlock cannot occur.


Related Solutions

Stata command for running an RDD with 2 treamtents and cut-off lines
Stata command for running an RDD with 2 treamtents and cut-off lines
Java try and catch problem public void method1(){ int[] array = new int[1]; try{ array[2] =...
Java try and catch problem public void method1(){ int[] array = new int[1]; try{ array[2] = 0;} catch(ArithmeticException e){array[2] = 0} // ? finally{ return 0;}} Could you please tell me why the line with the question mark will not report an error?
Lab 1. Java and the Command Prompt a) Visit the Java SE JDK website and see...
Lab 1. Java and the Command Prompt a) Visit the Java SE JDK website and see which version of Java you need to download. b) If granted permissions, try to see how to modify environment variables (PATH and CLASSPATH). c) Open the command prompt/shell. Use cd and dir (ls on UNIX-like systems) commands to navigate your file system and see what files do you have in different locations e.g. on your flash drive. Pay attention to the file extensions. d)...
(Using C++ create a Car Instrument Simulator) Car Instrument Simulator Create the following classes: Car, Odometer,...
(Using C++ create a Car Instrument Simulator) Car Instrument Simulator Create the following classes: Car, Odometer, FuelGauge. The Car class allows for the instantiation of a Car object. The Car object will contain (via composition) an Odometer object, and a FuelGauge object. The Car object will also include "make", "model", and "color" as string properties (instance variables). In the Car constructor method, you will create a FuelGauge object, passing 15 as an argument into the FuelGauge constructor indicating the number...
*IN JAVA* EXCEPTION HANDLING Concept Summary: 1. Use of try… catch in a program 2. Define...
*IN JAVA* EXCEPTION HANDLING Concept Summary: 1. Use of try… catch in a program 2. Define an exception class and call it from the driver program. For this lab you will complete two parts. Part (a) of the lab implements try… catch and uses an existing exception in C# or in Java. Write a program that implements an ArrayIndexOutOfBounds error. Part (b) writes a program that converts a time from 24-hour notation to 12-hour notation. Assume the user will enter...
Modify the following program. Add using Exception handing and polymorphism. try-catch block, Finally block in java...
Modify the following program. Add using Exception handing and polymorphism. try-catch block, Finally block in java * description of class Driver here. *these is the main class where it acts like parent class. Compiler will execute firstly static method. import java.util.Scanner; public class Driver {     public static void main (String[] args){         Scanner stdIn = new Scanner(System.in);         String user;         String computer;         char a = 'y';         do {             System.out.println("What kind of Computer would you like?");...
(Complete Using Ubuntu) Please try each command in Linux system, and get screenshots (you may put...
(Complete Using Ubuntu) Please try each command in Linux system, and get screenshots (you may put multiple commands in one screenshot) which can show how actually each command runs. Also, give a brief description (one or two sentences) for each command. For the commands which have multiple switches/parameters, please try one popular switch/parameter. Linux Commands: rm,cp ,mv (name), ld, ftp, more, less, cat (date), tar, top, ps (name), kill, df, last, patch, mkdir (date)
Topic is relates to Java programming! Code using java GUI 2. Create the following controls: a)...
Topic is relates to Java programming! Code using java GUI 2. Create the following controls: a) a TextField b) a Button c) a Text d) a Label 3. create the following container and put them the above controls: a) a VBox controller b) a BorderPane controller c) a GridPane
In MPLAB write and compile (using the simulator) an assembly language program with the following functionality:...
In MPLAB write and compile (using the simulator) an assembly language program with the following functionality: Configures pin RA2 of the PIC24to be an output to control an attached LED. Configures pin RB13 of the PIC24 to be an input to read the value on an attached switch (this switch will connect to ground when pressed). Configures pin RB13 to use the internal pull-up resistor. After configuration, the LED will be "off" when the push-button is pressed, and "on" when...
The program should be able to do the following: In Java accepts one command line parameter....
The program should be able to do the following: In Java accepts one command line parameter. The parameter specifies the path to a text file containing the integers to be sorted. The structure of the file is as follows: There will be multiple lines in the file (number of lines unknown). Each line will contain multiple integers, separated by a single whitespace. reads the integers from the text file in part a into an array of integers. sort the integers...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT