Process ID Assignment
An operating system’s pid manager is responsible for managing process identifiers. At process creation, the pid manager assigns the process a unique pid. When the process completes execution, it returns the pid to the pid manager which in turn may later reassign this pid to another process. Chapter 3 provides a full discussion of process identifiers. What is most important here is recognizing that process identifiers must be unique; no two active processes can have the same pid.
The first task in this assignment creates the pid manager whose implementation can simply be a single class. Of course, you can create any other classes you might need to implement the pid manager. You may use any data structure of your choice to represent the availability of process identifiers. One strategy adopts Linux’s approach of a bitmap in which a value of 0 at position i indicates that a process id of value i is available and a value of 1 indicates that the process id is currently in use. Use the following constants to identify the range of possible pid values: MIN_PID is 300 and MAX_PID is
Have your pid manager implement the following API for obtaining and releasing a pid:
int allocate map( ) – Creates and initializes a data structure for representing pids; returning 0 if unsuccessful or 1 if
int allocate pid( ) – Allocates and returns a pid; returns 1 if unable to allocate a pid, all pids are in
void release pid(int pid) – Releases a
The second task in this assignment consists of writing a multithreaded program that tests your pid manager. Implementing the threads uses either extends Thread or implements Runnable. Create a number of threads where each thread requests a pid, sleeps for a random period of time, releases the pid, and then terminates. Sleeping for a random period of time approximates the typical pid usage in which a new process acquires a pid, the process executes and then terminates, releasing the pid upon its termination. Download the java file needed for the assignment. A thread sleeps by calling the SleepUtilities.nap(duration) function, passing an integer value representing the number of seconds to sleep, where duration is a randomly generated integer between 60 and 300. Before sleeping, each thread should print out (on a new line) the message, “My PID is: x.”, where x is the actual pid for the thread.
Create a driver class and make the name of the driver class Assignment1 containing only one method:
public static void main(String args).
The main method itself is fairly short containing code to do the following:
Create the pid manager
For each thread, pass the pid manager into the thread and begin the execution of the
The main method needs to keep track of the threads and take care of each thread before it can end. The methods of the Thread class you'll need for this are join() and isAlive(). If the thread is dead then execute a join on it in order to properly dispose of that thread. If the thread is still alive then move on to the next thread. The main method keeps doing this check until the last remaining thread has died and been properly
You must declare public each class you create which means you define each class in its own
You must declare private the data members in every class you
You can only use extends in this assignment (extends Thread) when defining your thread class. Though, you don’t have to use “extends Thread” to define your thread class. Remember, “implements Runnable” is the other way in Java to define your thread
Tip: Make your program as modular as possible, not placing all your code in one .java file. You can create as many classes as you need in addition to the classes described above. Methods being reasonably small follow the guidance that "A function does one thing, and does it well." You will lose a lot of points for code readability if you don’t make your program as modular as possible. But, do not go overboard on creating classes and methods. Your common sense guides your creation of classes and
Do NOT use your own packages in your program. If you see the keyword package on the top line of any of your .java files then you created a package. Create every .java file in the src folder of your Eclipse project, if you’re using
Do NOT use any graphical user interface code in your program!
Do NOT type any comments in your program. If you do a good job of programming by following the advice in number 7 above then it will be easy for me to determine the task of your
DescriptionIn this final assignment, the students will demonstrate their ability to apply two majorconstructs of the C programming language – Fu
Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t
Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th
1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of
1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of