Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming Assignment #2 CSci 430 Spring 2019 Dates: Assigned: Monday February 4, 2019 Due: Wednesday February 20, 2019 (before Midnight) Objectives: Explore the Process state

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Programming Assignment #2 CSci 430 Spring 2019 Dates: Assigned: Monday February 4, 2019 Due: Wednesday February 20, 2019 (before Midnight) Objectives: Explore the Process state models from an implementation point of view. Practice using basic queue data types and implementing in C. Use C/C++ data structures to implement a process control block and round robin scheduling queues. Learn about Process switching and multiprogramming concepts. Description: In this assignment you will simulate a Three-State process model (ready, running and blocked) and a simple process control block structure as dis- cussed in Chapter 3. Your program will read input and directives from a file. The input describes a time sequence of events that occur. These are the full set of events you will simulate: Event Description The processor executes for 1 time step the currently running process new A new process is created and put at tail of the ready queue done The currently running process has finished wait X The currently running process has done an I/O operation and is waiting on event X event X Event X has occurred, the process waiting on that event should be made ready The input file will simply be a list of events that occur in the system, in the order they are to occur. For example: ----- simulation-01.sim ----- new cpu cpu cpu new cpu cpu cpu cpu wait 1 cpu cpu event 1 cpu cpu done cpu cpu cpu cpu exit Your task is to read in the events, and simulate the creation and execution of processes in the system as they move through the various three-states of their process life cycle. You need to: Define a simple process control block (PCB) to hold information about all processes currently running in your system. The PCB can be a simple C structor a C++ class. At a minimum you need to have a field for the process identifier and the process state (Ready, Running or Blocked). You need to also keep track of the time step that the process entered the system, and the number of steps the process has been running. Minimal credit will be given to programs that at least handle new events and create a process in a simulated PCB. You probably need a list or an array to hold the current processes that have been created and are being managed by your simulated system . You will need a ready queue of some kind. You should use a C++ Standard Template Library (STL) container to manage your ready queue. . You will need to implement a simple dispatcher function. When ever a cpu event occurs, and no process is currently running, you should select the next Ready process from the head of your ready queue and start it running on the processor, . You need to also implement a simple time slicing mechanism. The time slice value to use will be passed into your program when it is started. At the end of a cpu cycle, you should check if the currently running process has executed for its full time quantum. In that case, the currently running process should timeout, and be returned to the end of the Ready queue, new events should cause a new process to be created (including creating its PCB and filling it in). New processes should be placed on the tail of the ready queue after being created. You should assign each new process a process identifier. The process identifier should be a simple integer value, and you should start numbering processes from 1. For a done event, if a process is currently running it should then be released. It should be removed from the CPU, and not placed back on the ready or blocked queue. If a done occurs when the CPU is idle, then nothing will happen as a result of this event. A wait event simulates the currently running process performing some I/O operation. If a wait occurs, the currently running process should become blocked and put on the blocked queue. You also need an entry in the PCB so you know what event the process is waiting for. The wait event is followed by an integer number, which is an indication of the type of event the process has requested. Likewise the event directive simulates the finishing of some I/O oper- ation. When an event occurs, you should scan your blocked processes and make any process ready that was waiting on that event. The in- teger value following an event indicates the type of event that just occurred You have been given some example event sequences simulation-01.sim. simulation-02.sim, etc.) along with the expected output for those sequence of events simulation-01.res, simulation-02.res, etc.). The output of your program should be sent to standard output. The correct output for the simulation-01.sim simulation is: Time: 1 CPU (currently running): pid=1, state=RUNNING, start=1, slice=1, Ready Queue: EMPTY Blocked Queue: EMPTY Time: 2 CPU (currently running): pid=1, state=RUNNING, start=1, slice=2, Ready Queue: EMPTY Blocked Queue: EMPTY Time: 3 CPU (currently running): pid=1, state=RUNNING, start=1, slice=3, Ready Queue: EMPTY Blocked Queue: EMPTY Time: 4 CPU (currently running): pid=1, state=RUNNING, start=1, slice=4, Ready Queue: pid=2, state=READY, Start=4, slice=0, Blocked Queue: EMPTY Time: 5 CPU (currently running): pid=1, state =RUNNING, start=1, slice=5, Ready Queue: pid=2, state=READY Start=4, slice=0, Blocked Queue: EMPTY Time: 6 CPU (currently running): pid=2, state=RUNNING, start=4, slice=1, Ready Queue: pid=1, state=READY Start=1, slice-5, Blocked Queue: EMPTY Time: 7 CPU (currently running): pid=2, State=RUNNING, Start=4, slice=2, Ready Queue: pid=1, state=READY, Start=1, slice=5, Blocked Queue: EMPTY Time: 8 CPU (currently running): pid=1, State=RUNNING, Start=1, slice=1, Ready Queue : EMPTY Blocked Queue: pid=2, state=BLOCKED, Start=4, slice=2, event=1 Time: 9 CPU (currently running): pid=1, state=RUNNING, start=1, slice=2, Ready Queue: EMPTY Blocked Queue: pid=2, State=BLOCKED, start=4, slice=2, event=1 Time: 10 CPU (currently running): pid=1, state=RUNNING, start=1, slice=3, Ready Queue: pid=2, State=READY Start=4, slice=2, Blocked Queue: EMPTY Time: 11 CPU (currently running): pid=1, state=RUNNING, start=1, slice=4, Ready Queue: pid=2, state=READY, Start=4, slice=2, Blocked Queue: EMPTY Time: 12 CPU (currently running): pid=2, State=RUNNING, start=4, slice=1, Ready Queue : EMPTY Blocked Queue: EMPTY Time: 13 CPU (currently running): pid=2, State=RUNNING, Start=4, slice=2, Ready Queue: EMPTY Blocked Queue: EMPTY Time: 14 CPU (currently running): pid=2, state-RUNNING, start=4, slice-3, Ready Queue: EMPTY Blocked Queue: EMPTY Time: 15 CPU (currently running): pid=2, state=RUNNING, start=4, slice=4, Ready Queue: EMPTY Blocked Queue: EMPTY Your output to standard out should look exactly the same as this output (i.e, if I do a diff and your program is generating the correct output, then there will be no difference between the output your program generates and the above output format). The output is generated by displaying the system state after each cpu cycle executes. Basically we print out the system time. Then we show which process (if any) is currently running on the CPU or say it is IDLE if no process is running). Then we display the queue of processes currently on the Ready and Blocked qu eu es. Note that the qu eu es are displayed in order. The top of the output corresponds to the head of the queue. Thus when a new process is dispatched, the next one selected should be the first process listed from the ready queue in the previous system cycle. I have given you some template code (p2-st art.cpp) to get you started The code is meant to be run from the command line, thus from a shell or dos prompt you would do something like: $ p2-start simulation-01. sim 5 i.e, the program expects two parameters on the command line, which should be the name of a file that holds the events to be simulated, and the value to be used for the time slice quantum. If you need to test your program and can't figure out how to invoke running it from the command line, you can change the line in 'p2-st art.cpp' to explicitly run a particular simulation file, like this: run Simulation ("simulation-01. sim", time_slice-quantum) However, you need to make sure that your program correctly works using the command line invocation, as shown in 'p2-st art.cpp I have given some template code to get you started in the file called p2-st art.cpp. I have already provided you with the code needed in order to correctly parse the command line parameters for the program, and to open and read in the simulation file events. Your job is to implement the necessary actions and data structures to handle the simulated events described. The run Simulation () in 'p2-st art.cpp holds example code and indicates locations where you need to write your own functions to implement the simulation. You can use this as a starting point to implement your solution. Assignment Submission and Requirements All source files you create for you solution (.c or .cpp/c++ and .h header files) should be uploaded to the My Leo Online submission folder created for this assignment by the deadline. You should not attach any files besides the source files containing your C/C++ code. But you should make sure you attach all needed files you create to your submission, so that I can compile and run your solution. You are required to write the program in standard C/C++ programming language. You should use a relatively recent version of the C/C++ compiler (C90 C++98 is fine, or the more recent C99 C++11 will also be acceptable) and/or recent IDE that has an up to date compiler. You should only use standard C/C++ libraries, do not use Microsoft specific or other third-party developed external libraries. This page http://en.cppreference.com/w/ provides a good up to date reference of the libraries in the standard C++ and C languages. You may use the C++ standard template library containers (like the list and queue items) to implement the ready queue you need. We will go over a simple implementation of a queue using pointers and or arrays in dass, if you would like an example implementation in plain C that might be simpler to use than learning the STL. Programming Assignment #2 CSci 430 Spring 2019 Dates: Assigned: Monday February 4, 2019 Due: Wednesday February 20, 2019 (before Midnight) Objectives: Explore the Process state models from an implementation point of view. Practice using basic queue data types and implementing in C. Use C/C++ data structures to implement a process control block and round robin scheduling queues. Learn about Process switching and multiprogramming concepts. Description: In this assignment you will simulate a Three-State process model (ready, running and blocked) and a simple process control block structure as dis- cussed in Chapter 3. Your program will read input and directives from a file. The input describes a time sequence of events that occur. These are the full set of events you will simulate: Event Description The processor executes for 1 time step the currently running process new A new process is created and put at tail of the ready queue done The currently running process has finished wait X The currently running process has done an I/O operation and is waiting on event X event X Event X has occurred, the process waiting on that event should be made ready The input file will simply be a list of events that occur in the system, in the order they are to occur. For example: ----- simulation-01.sim ----- new cpu cpu cpu new cpu cpu cpu cpu wait 1 cpu cpu event 1 cpu cpu done cpu cpu cpu cpu exit Your task is to read in the events, and simulate the creation and execution of processes in the system as they move through the various three-states of their process life cycle. You need to: Define a simple process control block (PCB) to hold information about all processes currently running in your system. The PCB can be a simple C structor a C++ class. At a minimum you need to have a field for the process identifier and the process state (Ready, Running or Blocked). You need to also keep track of the time step that the process entered the system, and the number of steps the process has been running. Minimal credit will be given to programs that at least handle new events and create a process in a simulated PCB. You probably need a list or an array to hold the current processes that have been created and are being managed by your simulated system . You will need a ready queue of some kind. You should use a C++ Standard Template Library (STL) container to manage your ready queue. . You will need to implement a simple dispatcher function. When ever a cpu event occurs, and no process is currently running, you should select the next Ready process from the head of your ready queue and start it running on the processor, . You need to also implement a simple time slicing mechanism. The time slice value to use will be passed into your program when it is started. At the end of a cpu cycle, you should check if the currently running process has executed for its full time quantum. In that case, the currently running process should timeout, and be returned to the end of the Ready queue, new events should cause a new process to be created (including creating its PCB and filling it in). New processes should be placed on the tail of the ready queue after being created. You should assign each new process a process identifier. The process identifier should be a simple integer value, and you should start numbering processes from 1. For a done event, if a process is currently running it should then be released. It should be removed from the CPU, and not placed back on the ready or blocked queue. If a done occurs when the CPU is idle, then nothing will happen as a result of this event. A wait event simulates the currently running process performing some I/O operation. If a wait occurs, the currently running process should become blocked and put on the blocked queue. You also need an entry in the PCB so you know what event the process is waiting for. The wait event is followed by an integer number, which is an indication of the type of event the process has requested. Likewise the event directive simulates the finishing of some I/O oper- ation. When an event occurs, you should scan your blocked processes and make any process ready that was waiting on that event. The in- teger value following an event indicates the type of event that just occurred You have been given some example event sequences simulation-01.sim. simulation-02.sim, etc.) along with the expected output for those sequence of events simulation-01.res, simulation-02.res, etc.). The output of your program should be sent to standard output. The correct output for the simulation-01.sim simulation is: Time: 1 CPU (currently running): pid=1, state=RUNNING, start=1, slice=1, Ready Queue: EMPTY Blocked Queue: EMPTY Time: 2 CPU (currently running): pid=1, state=RUNNING, start=1, slice=2, Ready Queue: EMPTY Blocked Queue: EMPTY Time: 3 CPU (currently running): pid=1, state=RUNNING, start=1, slice=3, Ready Queue: EMPTY Blocked Queue: EMPTY Time: 4 CPU (currently running): pid=1, state=RUNNING, start=1, slice=4, Ready Queue: pid=2, state=READY, Start=4, slice=0, Blocked Queue: EMPTY Time: 5 CPU (currently running): pid=1, state =RUNNING, start=1, slice=5, Ready Queue: pid=2, state=READY Start=4, slice=0, Blocked Queue: EMPTY Time: 6 CPU (currently running): pid=2, state=RUNNING, start=4, slice=1, Ready Queue: pid=1, state=READY Start=1, slice-5, Blocked Queue: EMPTY Time: 7 CPU (currently running): pid=2, State=RUNNING, Start=4, slice=2, Ready Queue: pid=1, state=READY, Start=1, slice=5, Blocked Queue: EMPTY Time: 8 CPU (currently running): pid=1, State=RUNNING, Start=1, slice=1, Ready Queue : EMPTY Blocked Queue: pid=2, state=BLOCKED, Start=4, slice=2, event=1 Time: 9 CPU (currently running): pid=1, state=RUNNING, start=1, slice=2, Ready Queue: EMPTY Blocked Queue: pid=2, State=BLOCKED, start=4, slice=2, event=1 Time: 10 CPU (currently running): pid=1, state=RUNNING, start=1, slice=3, Ready Queue: pid=2, State=READY Start=4, slice=2, Blocked Queue: EMPTY Time: 11 CPU (currently running): pid=1, state=RUNNING, start=1, slice=4, Ready Queue: pid=2, state=READY, Start=4, slice=2, Blocked Queue: EMPTY Time: 12 CPU (currently running): pid=2, State=RUNNING, start=4, slice=1, Ready Queue : EMPTY Blocked Queue: EMPTY Time: 13 CPU (currently running): pid=2, State=RUNNING, Start=4, slice=2, Ready Queue: EMPTY Blocked Queue: EMPTY Time: 14 CPU (currently running): pid=2, state-RUNNING, start=4, slice-3, Ready Queue: EMPTY Blocked Queue: EMPTY Time: 15 CPU (currently running): pid=2, state=RUNNING, start=4, slice=4, Ready Queue: EMPTY Blocked Queue: EMPTY Your output to standard out should look exactly the same as this output (i.e, if I do a diff and your program is generating the correct output, then there will be no difference between the output your program generates and the above output format). The output is generated by displaying the system state after each cpu cycle executes. Basically we print out the system time. Then we show which process (if any) is currently running on the CPU or say it is IDLE if no process is running). Then we display the queue of processes currently on the Ready and Blocked qu eu es. Note that the qu eu es are displayed in order. The top of the output corresponds to the head of the queue. Thus when a new process is dispatched, the next one selected should be the first process listed from the ready queue in the previous system cycle. I have given you some template code (p2-st art.cpp) to get you started The code is meant to be run from the command line, thus from a shell or dos prompt you would do something like: $ p2-start simulation-01. sim 5 i.e, the program expects two parameters on the command line, which should be the name of a file that holds the events to be simulated, and the value to be used for the time slice quantum. If you need to test your program and can't figure out how to invoke running it from the command line, you can change the line in 'p2-st art.cpp' to explicitly run a particular simulation file, like this: run Simulation ("simulation-01. sim", time_slice-quantum) However, you need to make sure that your program correctly works using the command line invocation, as shown in 'p2-st art.cpp I have given some template code to get you started in the file called p2-st art.cpp. I have already provided you with the code needed in order to correctly parse the command line parameters for the program, and to open and read in the simulation file events. Your job is to implement the necessary actions and data structures to handle the simulated events described. The run Simulation () in 'p2-st art.cpp holds example code and indicates locations where you need to write your own functions to implement the simulation. You can use this as a starting point to implement your solution. Assignment Submission and Requirements All source files you create for you solution (.c or .cpp/c++ and .h header files) should be uploaded to the My Leo Online submission folder created for this assignment by the deadline. You should not attach any files besides the source files containing your C/C++ code. But you should make sure you attach all needed files you create to your submission, so that I can compile and run your solution. You are required to write the program in standard C/C++ programming language. You should use a relatively recent version of the C/C++ compiler (C90 C++98 is fine, or the more recent C99 C++11 will also be acceptable) and/or recent IDE that has an up to date compiler. You should only use standard C/C++ libraries, do not use Microsoft specific or other third-party developed external libraries. This page http://en.cppreference.com/w/ provides a good up to date reference of the libraries in the standard C++ and C languages. You may use the C++ standard template library containers (like the list and queue items) to implement the ready queue you need. We will go over a simple implementation of a queue using pointers and or arrays in dass, if you would like an example implementation in plain C that might be simpler to use than learning the STL

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mastering Apache Cassandra 3 X An Expert Guide To Improving Database Scalability And Availability Without Compromising Performance

Authors: Aaron Ploetz ,Tejaswi Malepati ,Nishant Neeraj

3rd Edition

1789131499, 978-1789131499

More Books

Students also viewed these Databases questions

Question

=+3. If you have identified impediments, how can you overcome them?

Answered: 1 week ago

Question

Choosing Your Topic Researching the Topic

Answered: 1 week ago

Question

The Power of Public Speaking Clarifying the

Answered: 1 week ago