SlideShare a Scribd company logo
1 of 74
HS2021 Database Design and Use
Week 2 - 2020 Tutorial
Date:
Instructions:
This exam has three (3) questions.
You are expected to select one question out of three (3)
questions and to submit your answer via the blackboard
assessment system.
Assessment Weight:
This test accounts for five per cent (5%) of total marks.
Total marks for the paper
5 marks
Question A: Create the Entity-Relationship Diagram and the
Relational Schema for the following scenario
BestBank prides itself on having up-to-date information on the
current account balance of its customers. To do this, BestBank
relies on a company-wide information system. Customers are
the heart of the BestBank information system. Customers are
characterized by their customer number (unique), first name,
last name, address, and date of birth. A customer can have
multiple accounts into the BestBank information system.
Accounts are characterized by their account number (unique),
account type (i.e. everyday, savings, business) and amount and
they must be assigned to a specific customer. To keep track of
their spending habits BestBank customers can review all the
transactions executed using their accounts. A transaction must
be associated with a specific account, and each account can
have multiple transactions. Finally, each transaction is
characterized by a transaction id (unique), a transaction type
(i.e. withdraw or deposit) and the transaction amount.
Question B: Create the Entity-Relationship Diagram and the
Relational Schema for the following scenario
BestDelivery prides itself on having up-to-date information on
the status of shipped item. To do this, BestDelivery relies on a
company-wide information system. Items are the heart of the
BestDelivery information system. Items are characterized by
their item code (unique), delivery status, and destination
address. Items are assigned to couriers who are in charge of
their delivery. A courier delivers several items in a day.
Couriers are characterized by their employee number (unique),
first name, last name, and driving license.
Question C: Create the Entity-Relationship Diagram and the
Relational Schema for the following scenario
BestFreelancer prides itself on having the most efficient
platform through which is possible to find freelancers for any
type of work. Freelancers can freely register on the platform
and provide information about all the projects they have
completed. To do this, BestFreelancer relies on a company-wide
information system. Freelancers are the heart of the
BestFreelancer information system. Freelancers are
characterized by their profile code (unique), first name, last
name, and email. Freelancers can list, within their profile, as
many projects as they want. Projects are characterized by their
project code (unique), start date, end date, project title, and
project description.
Student Name:
_____________________________________________________
Student ID: ____________________________
HS2021 Database Design and use
Week 2 - 2020
10
p3-start.cppp3-start.cpp/** @file p3-start.cpp
*
* @author Your Name Here
*
* @assg Programming Assignment #3
*
* @desc Implement the deadlock detection algorithm. Given a
file
* that describes the current allocation A of resources in th
e
* system, and the current set of outstanding requests Q in
* the system, determine if a deadlock is present or not. U
se
* the algorithm given on p.276 in the Stallings textbook.
*
* @date March 05, 2018
*/
#include<stdlib.h>
#include<iostream>
#include<iomanip>
#include<fstream>
#include<string>
usingnamespace std;
// global constants
constint MAX_PROCESSES =10;// I won't test your algorithm
with simulations with more than 10 processes
constint MAX_RESOURCES =10;// nor will I give a simulation
to test with more than 10 resources
// simple struct to read in and hold the state of the system
typedefstruct
{
int numResources;
int numProcesses;
int available[MAX_RESOURCES];// V available vector
int alloc[MAX_PROCESSES][MAX_RESOURCES];// A allocati
on matrix
int request[MAX_PROCESSES][MAX_RESOURCES];// Q requ
est matrix
}State;
/** Read system state from file.
* Given a file, read the current system state from the file.
* The system state file is expected to hold the available vector
V
* the allocation matrix A and the request matrix Q.
*
* @param simfilename The name of the file to open and read st
ate & request
* from.
* @return state A new State structure is allocated and filled wit
h the
* system state from the file. A pointer to this allocated sy
stem
* state structure is returned as a result of calling this func
tion.
*/
State* readSystemState(char* statefilename)
{
ifstream simstatefile(statefilename);
State* state;
int r, p;
// If we can't open file, abort and let the user know problem
if(!simstatefile.is_open())
{
cout <<"Error: could not open system state file: "<< statefile
name
<< endl;
exit(1);
}
// dynamically allocate a new State structure, to be filled in and
returned
state =newState;
// Format of file is this (where m = numResource n = numProces
ses
// V = available vector
// A = allocation matrix and
// Q = request matrix)
// m n
// V1 V2 V3 ... Vm
// A11 A12 ... A1m
// ...
// An1 An2 ... Anm
// Q11 Q12 ... Q1m
// ...
// Qn1 Qn2 ... Qnm
// First line, get m (numResources) and n (numProcesses)
simstatefile >> state->numResources >> state->numProcesses;
// Next line contains the available vector V
for(r =0; r < state->numResources; r++)
{
simstatefile >> state->available[r];
}
// Next n lines contain the allocation matrix A
for(p =0; p < state->numProcesses; p++)
{
for(r =0; r < state->numResources; r++)
{
simstatefile >> state->alloc[p][r];
}
}
// Next n lines contain the request matrix Q
for(p =0; p < state->numProcesses; p++)
{
for(r =0; r < state->numResources; r++)
{
simstatefile >> state->request[p][r];
}
}
// return the newly allocated and filled in system state
return state;
}
/** Display a vector
* Display a state vector to standard output
*
* @param len The number of items in the vector
* @param v An array of integers of len items
*/
void displayVector(int len,int v[])
{
int i;
// Display a header
for(i =0; i < len; i++)
{
cout <<"R"<< i <<" ";
}
cout << endl;
// Display values
for(i =0; i < len; i++)
{
cout << setw(2)<< v[i]<<" ";
}
cout << endl;
}
/** Display a matrix
* Display a state matrix to standard output
*
* @param rows The number of rows in the matrix
* @param cols The number of cols in the matrix
* @param m A 2 dimensional array of rows x cols integers
*/
void displayMatrix(int rows,int cols,int v[MAX_PROCESSES][
MAX_RESOURCES])
{
int r, c;
// display column headers
cout <<" ";// extra space over for row labels
for(c =0; c < cols; c++)
{
cout <<"R"<< c <<" ";
}
cout << endl;
// now display data in matrix
for(r =0; r < rows; r++)
{
cout <<"P"<< r <<" ";
for(c =0; c < cols; c++)
{
cout << setw(2)<< v[r][c]<<" ";
}
cout << endl;
}
cout << endl;
}
/** Display state
* Display the values of the resource vectors and matrices in the
indicated
* state structure
*
* @param state A pointer to a State struct whose info we shoul
d display on stdout.
*/
void displayState(State* s)
{
cout <<"numResources (m) = "<< s->numResources <<" ";
cout <<"numProcesses (n) = "<< s-
>numProcesses << endl << endl;
cout <<"Available vector V:"<< endl;
displayVector(s->numResources, s->available);
cout << endl;
cout <<"Allocation matrix A: "<< endl;
displayMatrix(s->numProcesses, s->numResources, s->alloc);
cout << endl;
cout <<"Request matrix Q: "<< endl;
displayMatrix(s->numProcesses, s->numResources, s-
>request);
cout << endl;
}
/** The deadlock detector
* The starting point for implementation of the deadlock detecti
on algorithm.
* We open and read in the allocation matrices here, then perfor
m the deadlock detection.
*
* @ param statefilename A string with the name of the file hol
ding the A and Q system state matrices
*/
void detectDeadlock(char* statefilename)
{
State* state;
state = readSystemState(statefilename);
// I have provided some example routines to read and display sy
stem state, implemented as a plain
// C struct using C 1 and 2 dimensional arrays. You can uncom
ment out the following, and/or use
// the displayMatrix() and displayVector() functions to help you
debug. But make sure you
// remove or comment back up any statements after you are done
debugging.
displayState(state);
// You need to implement your solution here. I would recomme
nd you use functions for each of
// these steps.
// Step 1: Set up a data structure that records marked/unmarked
// processes. All processes are initially unmarked Search
// through the allocation matrix to find rows of all 0, and
// mark corresponding processes in your mark structure
// Step 2: Create a temporary vector W. Copy contents of availa
ble
// vector V to W. Suggestion: create a function called
// copyVector, that takes a vector as its parameter, and returns
// a new vector.
// Need to put Steps 3 and 4 in a loop
// Step 3: Find index i such that process i is currently unmarked,
// and the ith row of Q is less than or equal to W. If no
// such process is found, need to terminate algorithm/loop.
// Suggestion: write a function that takes Q and W, and
// returns either i (index of process meeting criteria) or
// -1
// Step 4: If a row was found (e.g. i was a valid process that met
// criteria of step 3), mark process i and add the
// correspoinding row of allocation matrix to W. Loop bac
k
// to beginning of step 3.
// Step 5: after loop finishes,
// if (your marked/unmarked processes contains unmarked proce
sses)
// {
// cout << "Deadlock";
// // loop through your marked/unmarked structure, print out al
l unmarked processes as P1, P2, etc.
// cout << endl;
// }
// else // all processes were marked, so no deadlock
// {
// cout << "No Deadlock" << endl;
// }
}
/** Main entry point of deadlock detection.
* The main entry point of the deadlock detection program. Thi
s function
* checks the command line arguments, and calls the detection f
unction if correct
* arguments were supplied. We expect a single command line
argument
* which is the name of the file holding the allocation and reque
st matrices
* of the current state of the system.
*
* @param argc The argument count
* @param argv The command line argument values. We expect
argv[1] to be the
* name of a file in the current directory holding A and
Q matrices.
*/
int main(int argc,char** argv)
{
if(argc !=2)
{
cout <<"Error: expecting state matrix file as first command li
ne parameter"<< endl;
cout <<"Usage: "<< argv[0]<<" system-state.sim"<< endl;
exit(1);
}
detectDeadlock(argv[1]);
// if don't want to use command line do following. Need to reco
mpile by hand since file
// name to get simulated events from is hard coded.
// Make sure you revert back to using command line before sub
mitting your program.
//detectDeadlock("state-01.sim");
}
prog-03.pdf
CSci 430: Programming Project #3
Deadlock Detection
Spring 2019
Dates:
Assigned: Monday February 25, 2019
Due: Wednesday March 13, 2019 (before Midnight)
Objectives:
� Learn more about Deadlock algorithms.
� Better understand how we can algorithmically detect
deadlocks on a
system.
� Use C/C++ to implement vector and matrix data structures,
get prac-
tice in creating and using such data structures in C/C++.
Description:
Our textbook gives the following algorithm (pg. 276) for
algorithmically
detecting if a deadlock is present or not in a system. It requires
that the
system keep an Allocation matrix A, listing which resources are
currently
allocated to which processes, and the available vector V, which
gives the
amount of each resource currently available in the system. In
addition, the
deadlock detection algorithm requies a request matrix Q, which
keeps track
of the amount of each resource each process is currently
requesting from the
system. The algorithm is:
1. Mark each process that has a row in the Allocation matrix of
all zeros.
2. Initialize a temporary vector W to equal the Available vector
A.
1
3. Find an index i such that process i is currently unmarked and
the i th
row of Q is less than or equal to W. That is, Qik ≤ Wk, for 1 ≤ k
≤ m.
If no such row is found, terminate the algorithm.
4. If such a row is found, mark process i and add the
corresponding row of
the allocation matrix to W. That is, set Wk = Wk+Aik, for 1 ≤ k
≤ m.
Return to step 3.
A deadlock exists if and only if there are unmarked processes at
the end
of the algorithm. Each unmarked process is deadlocked.
In this assignment we will implement the deadlock detection
algorithm.
Your program will be given a �le that describes the A
allocation matrix
and the Q request matrix, representing the current state of all
allocations
and requested allocations in the system. Your program will
implement the
deadlock detection algorithm described above. The result of
your program
will be one of 2 outputs:
1. If no deadlock exists, the program will display No Deadlock
on stan-
dard output.
2. If a deadlock does exist, the program will display Deadlock:
P0, P1,
P2 on standard output, where P0, P1, P2 are the processes that
the
algorithm determined to be deadlocked in the system.
State simulation �le formats
I have provided a p3-start.cpp template that can open up and
read in the
process/resource state simulation �les used for this assignment.
Here we
discuss a bit more the format of these �le. I have provided 2 or
3 exam-
ple simulations, with expected correct answers, for you to use to
test your
implementations with.
The input �les needed for this assignment need to contain the
information
found in the V available vector and the A allocation and Q
request matrices.
In the following I use r as the number of resources and p as the
number of
processes. Thus the general format of the input �le is:
r p
V1 V2 V3 ... Vr
A11 A12 ... A1r
...
Ap1 Ap2 ... Apr
2
Q11 Q12 ... Q1r
...
Qp1 Qp2 ... Qpr
For example, the example of the deadlock detection algorithm
given on
page 277 has a system with r=5 resources and p=4 processes.
The V, A and
Q vector/matrices are shown on that page. The input �le for the
current
state of the system shown on page 277 would be
5 4
0 0 0 0 1
1 0 1 1 0
1 1 0 0 0
0 0 0 1 0
0 0 0 0 0
0 1 0 0 1
0 0 1 0 1
0 0 0 0 1
1 0 1 0 1
The function named readSystemState() in your template p2-
start.cpp
code expects a �le of this format, and reads it into a State
structure for you.
Running Simulations
The following is a discussion of the expected output of your
program. Your
program must work from the command line, and expect a single
parameter,
the name of the state simulation input �le, as its input. Your
program
should display only a single line to standard output as a result
of running it.
If the system, described in the state input �le is not deadlocked,
the program
should simply state there was no deadlock to standard output:
$ p3.exe state-02.sim
No Deadlock
On the other hand, if your program is deadlocked, it should say
that it
detected a deadlock, and it should print out the processes that
are deadloked
to standard output:
$ p3.exe state-01.sim
Deadlock: P0, P1,
3
I have provided 2 or 3 example input state �les, named state-
01.sim,
state-02.sim, etc. I have also provided the correct and expected
output for
these simulations, named state-01.res, state-02.out, etc.
4
state-01.sim
5 4
0 0 0 0 1
1 0 1 1 0
1 1 0 0 0
0 0 0 1 0
0 0 0 0 0
0 1 0 0 1
0 0 1 0 1
0 0 0 0 1
1 0 1 0 1
state-01.res
state-02.sim
5 4
0 1 0 0 1
1 0 1 1 0
1 1 0 0 0
0 0 0 1 0
0 0 0 0 0
0 1 0 0 1
0 0 1 0 1
0 0 0 0 1
1 0 1 0 1
state-02.res
state-03.sim
8 7
0 2 0 1 2 3 1 0
1 0 1 0 0 0 1 1
0 0 0 2 1 0 0 0
1 0 0 0 0 2 0 0
0 0 0 0 1 0 0 0
0 1 0 0 1 0 0 1
0 1 0 0 0 0 0 0
0 0 0 0 0 0 1 0
0 1 0 0 0 0 0 0
0 0 0 1 0 0 0 0
0 0 1 0 0 0 0 0
0 0 0 0 0 2 0 0
0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 1
0 0 0 0 1 0 0 0
state-03.res
state-04.sim
8 7
0 0 0 1 2 3 1 0
1 0 1 0 0 0 1 1
0 0 0 2 1 0 0 0
1 0 0 0 0 2 0 0
0 0 0 0 1 0 0 0
0 1 0 0 1 0 0 1
0 1 0 0 0 0 0 0
0 0 0 0 0 0 1 0
0 1 0 0 0 0 0 0
0 0 0 1 0 0 0 0
0 0 1 0 0 0 0 0
0 0 0 0 0 2 0 0
0 1 0 0 0 0 1 0
0 0 0 0 0 0 0 1
0 0 0 0 1 0 0 0
state-04.res
state-05.sim
10 10
1 0 1 0 2 2 1 2 2 1
1 0 1 0 0 0 0 2 0 0
0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 1 0 0 1 0
0 0 0 0 1 0 1 0 0 1
0 0 0 2 0 0 0 0 1 0
0 0 0 0 0 0 0 0 1 0
0 1 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 1
0 0 0 1 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 1 1 1 0 1
1 1 0 1 0 0 0 0 0 0
0 0 0 0 1 0 0 0 1 1
1 0 0 1 0 1 0 0 0 0
0 0 1 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
1 0 0 0 1 1 0 0 0 0
1 0 0 0 0 0 0 1 0 0
1 0 0 0 0 0 0 0 0 0
state-05.res
state-06.sim
10 10
1 0 0 0 0 2 0 2 2 1
1 0 1 0 0 0 0 2 0 0
0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 1 0 0 1 0
0 0 0 0 1 0 1 0 0 1
0 0 0 2 0 0 0 0 1 0
0 0 0 0 0 0 0 0 1 0
0 1 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 1
0 0 0 1 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 1 1 1 0 1
1 1 0 1 0 0 0 0 0 0
0 0 0 0 1 0 0 0 1 1
1 0 0 1 0 1 0 0 0 0
0 0 1 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
1 0 0 0 1 1 0 0 0 0
1 0 0 0 0 0 0 1 0 0
1 0 0 0 0 0 0 0 0 0
state-06.res
state-07.sim
10 10
0 0 0 1 0 0 0 1 0 0
0 0 0 0 0 0 0 0 1 0
0 0 2 0 1 0 0 0 0 0
0 1 0 0 1 0 1 0 0 0
0 0 0 1 0 0 0 0 0 0
0 1 0 0 0 0 1 1 0 0
0 0 1 0 0 0 0 0 1 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 1 0
0 1 0 1 0 0 0 0 0 0
0 0 1 0 0 1 0 0 1 0
1 0 0 0 0 1 0 1 0 0
1 0 0 0 0 1 0 0 0 0
1 0 0 0 0 1 0 0 1 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0
1 2 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 1 0 0
state-07.res
state-08.sim
10 10
0 1 1 1 0 1 0 1 0 0
0 0 0 0 0 0 0 0 1 0
0 0 2 0 1 0 0 0 0 0
0 1 0 0 1 0 1 0 0 0
0 0 0 1 0 0 0 0 0 0
0 1 0 0 0 0 1 1 0 0
0 0 1 0 0 0 0 0 1 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 1 0
0 1 0 1 0 0 0 0 0 0
0 0 1 0 0 1 0 0 1 0
1 0 0 0 0 1 0 1 0 0
1 0 0 0 0 1 0 0 0 0
1 0 0 0 0 1 0 0 1 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0
1 2 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 1 0 0
state-08.res
p5-start.cppp5-start.cpp/**
* @author Jane Student
* @cwid 123 45 678
* @class CSci 430, Spring 2018
* @ide Visual Studio Express 2010
* @date November 15, 2018
* @assg prog-04
*
* @description This program implements a simulation of proce
ss
* scheduling policies. In this program, we implement round-
robin
* scheduling, where the time slice quantum can be specified a
s
* as a command line parameter. And we also implement shor
test
* remaining time (SRT) scheduling policy
*/
#include<stdlib.h>
#include<iostream>
#include<iomanip>
#include<fstream>
#include<string>
#include<list>
usingnamespace std;
// global constants
// I won't test your round robin implementation with more than 2
0 processes
constint MAX_PROCESSES =20;
constint NO_PROCESS =0;
// Simple structure, holds all of the information about processes,
their names
// arrival and service times, that we are to simulate.
typedefstruct
{
string processName;
int arrivalTime;
int serviceTime;
// holds running count of time slices for current time quantum,
when
// serviceTime == quantum, time slice is up
int sliceTime;
// holds total number of time steps currently run, when == to
// serviceTime process is done
int totalTime;
// holds time when process finishes, used to calculate final stats,
// like T_r, T_r/T_s
int finishTime;
// a boolean flag, we will set this to true when the process is co
mplete
bool finished;
}Process;
// Process table, holds table of information about processes we a
re simulating
typedefstruct
{
int numProcesses;
Process* process[MAX_PROCESSES];
}ProcessTable;
/** Create process table
* Allocate memory for a new process table. Load the process
* information from the simulation file into a table with the proc
ess
* information needed to perform the simulation. At the same ti
me we
* initialize other information in process table for use in the
* simulation. Return the newly created ProcessTable
*
* @param processFilanem The name (char*) of the file to open
and read
* the process information from.
* @param processTable This is actually a return parameter. Th
is
* should be a pointer to an already allocated array of
* Process structure items. We will fill in this structure
* and return the process information.
*
* @returns ProcessTable* The newly allocated and initialized P
rocessTable
* structure.
*/
ProcessTable* createProcessTable(char* processFilename)
{
ifstream simprocessfile(processFilename);
ProcessTable* processTable;
int pid;
string processName;
int arrivalTime;
int serviceTime;
// If we can't open file, abort and let the user know problem
if(!simprocessfile.is_open())
{
cout <<"Error: could not open process simulation file: "
<< processFilename << endl;
exit(1);
}
// Format of file is
// ProcessName1 ArrivalTime1 ServiceTime1
// ProcessName2 ArrivalTime2 ServiceTime2
// ...
// ProcessNameN ArrivalTimeN ServiceTimeN
//
// Where the name is any arbitray string identifier, and ArrivalT
ime
// and ServiceTime are integer values
pid =0;
processTable =new(ProcessTable);
while(simprocessfile >> processName >> arrivalTime >> servic
eTime)
{
// allocate a new process to hold information
Process* process =new(Process);
processTable->process[pid]= process;
// load information into process read from simulation file
process->processName = processName;
process->arrivalTime = arrivalTime;
process->serviceTime = serviceTime;
// initialize other process information for the simulaiton
process->sliceTime =0;
process->totalTime =0;
process->finishTime =0;
process->finished =false;
pid++;
}
// Set the number of processes we need to simulate information i
n
// the process table
processTable->numProcesses = pid;
return processTable;
}
/** Display process table
* Convenience method, dump all of the information about the p
rocesses
* in a process table to stdout.
*
* @param processTable The table, a pointer to type ProcessTab
le
* struct, with the information we are to display
*/
void displayProcessTable(ProcessTable* processTable)
{
cout <<"Process Table num = "<< processTable-
>numProcesses << endl;
cout <<"PID Name Arrv Srvc"<< endl;
cout <<"------------------"<< endl;
for(int pid=0; pid < processTable->numProcesses; pid++)
{
Process* p = processTable->process[pid];
cout << setw(2)<< right << pid <<") ";
cout << setw(4)<< left << p->processName <<" ";
cout << setw(4)<< right << p->arrivalTime <<" ";
cout << setw(4)<< right << p->serviceTime <<" ";
cout << endl;
}
}
/** Round robin scheduler simulator
* The main routine for performing the round robin preemptive
* scheduler simulator. We expect the time quantum to already
be
* specified and given to us as the first parameter. The file nam
e
* with the process arrival and service time information is given
as
* the second parameter. We simulate preemptive round robin
* scheduling of all of the processes until there are no longer an
y
* processes left in the system (all processes have exceeded thei
r
* service time and have exited).
*
* @param processTable A pointer to a ProcessTable structure h
olding
* information about the processes, arrival times and duratio
ns
* that we are simulating execution of.
* @param quantum An integer value holding the time slice qua
ntum we
* are using for this simulation.
*/
void roundRobinScheduler(ProcessTable* processTable,int quan
tum)
{
// Implement the round robin scheduler here
cout <<"<roundRobinScheduler> entered, quantum: "<< quant
um << endl;
}
/** shortest remaining time simulator
* The main routine for performing the shortest remaining time
* preemptive scheduler simulator. The file name with the proc
ess
* arrival and service time information is given as the first
* parameter. We simulate preemptive shortest remaining time
* scheduling of all of the processes until there are no longer an
y
* processes left in the system (all processes have exceeded thei
r
* service time and have exited).
*
* @param processTable A pointer to a ProcessTable structure h
olding
* information about the processes, arrival times and duratio
ns
* that we are simulating execution of.
*/
void shortestRemainingTime(ProcessTable* processTable)
{
// Implement the shortest remaining time policy here
cout <<"<shortestRemainingTime> entered"<< endl;
}
/** Main entry point of round robin scheduler
* The main entry point of the round robin scheduler simulator.
The main funciton
* checks the command line arguments, and calls the simulation
function if correct
* arguments were supplied. We expect two command line argu
ments, which are the
* time slice quantum value we are to use for this preemptive sc
heduler simulation,
* and the name of the simulation file holding the process arriva
l and service
* time information.
*
* @param argc The argument count
* @param argv The command line argument values. We expect
argv[1] to be the
* time slice quantum parameter (int format) and argv[2
] to be the
* name of the process simulation file (charcter string)
*/
int main(int argc,char** argv)
{
string policy;
ProcessTable* processTable;
int quantum =0;
// If not all parameters provides, abort and let user know of prob
lem
if(argc <3|| argc >4)
{
cout <<"Error: expecting process simulation file and scheduli
ng policy as command line parameters"
<< endl;
cout <<"Usage: "<< argv[0]<<" process-
file.sim [rr|srt] [quantum]"<< endl;
exit(1);
}
// load process table and parse command line arguments
processTable = createProcessTable(argv[1]);
// just to confirm that process table loaded correctly. You shoul
d
// comment out or remove this as it is not asked for as part of th
e
// output for the assignment simulation
displayProcessTable(processTable);
// determine policy to simulate
policy.assign(argv[2]);
// perform simulation of indicated scheduling policy
if(policy =="rr")
{
if(argc !=4)
{
cout <<"Error: time quantum must be provided for round ro
bin `rr` scheduling policy"<< endl;
exit(1);
}
quantum = atoi(argv[3]);
if((quantum <=0)||(quantum >1000))
{
cout <<"Error: received bad time slice quantum parameter:
"<< argv[1]<< endl;
cout <<" valid values are integers in range from 1 to 10
00"<< endl;
exit(1);
}
roundRobinScheduler(processTable, quantum);
}
elseif(policy =="srt")
{
shortestRemainingTime(processTable);
}
else
{
cout <<"Error: unknown process scheduling policy: "<< polic
y << endl;
}
}
prog-05.pdf
Programming Assignment #5
CSci 430, Spring 2019
Dates:
Assigned: Monday April 15, 2019
Due: Wednesday May 1, 2019 (before Midnight)
Objectives:
� Understand short-term process scheduling.
� Work with data structures to implement a round-robin
scheduler.
� Look at e�ects of di�erent time slice quantum sizes on the
round-robin scheduling algorithm.
� Use C/C++ to implement vector and matrix data structures,
get practice in creating and using
such data structures in C/C++.
Description:
Our textbooks chapter 9 discusses several possible short-term
process scheduling policies. In this
programming assignment exercise we will implement two of the
preemptive policies, the simple shortest
remaining time policy (SRT) and the round-robin scheduler with
preemptive time slicing. Your program
will be given a simple input �le, indicating the process name,
its arrival time and its total service time,
the same as the process scheduling examples from our textbook
in Table 9.4 and Figure 9.5. You will
simulate the execution of the required schedulers. As in
previous assignments, you program will need
to work non-interactively and be callable from the command
line. The program will be provided with
the �le name of a �le with process information, in the format
discussed below. Your program will also
be given the time slicing quantum parameter it is to use for the
simulation, if round-robin scheduling
is selected. Your program will need to output the results of
running the set of simulated processes
using the selected scheduling policy with the indicated time
slice for the round-robin scheduler. Your
program will have to output its results exactly as shown below
in the required output format. Your
program will also need to calculate some summary statistics for
the simulated processes, including the
turnaround time and Tr/Ts ratio for each process, and the mean
Tr and Tr/Ts values for the given
simulation.
Process simulation �le formats
The �les with the information about the processes to be
simulated are fairly simple, and have the same
information that our textbook uses to illustrate the process
scheduling examples. Each simulation �le
contains multiple rows of data, where each row consists of the
process name, its arrival time, and its
service time. Here is an example:
1
A 0 3
B 2 6
C 4 4
D 6 5
E 8 2
This �le is named process-01.sim in the zip archive of �les I
have given you to get started on this
assignment. This is also the same set of processes and
start/service times used for all of the examples
in table 9.4 and �gure 9.5.
Running Simulations
As with previous assignments you are required to support using
your simulation from the command
line. Your program will take the name of the �le containing the
process information �rst. The next
parameter will be either 'rr' to perform round-robin scheduling,
or 'srt' if shortest remaining time policy
is to be simulated. Finally, a 3rd parameter will be supplied for
the round-robin scheduler, the time
slice quantum to use. An example of running your �nished
program should look like this:
$ ./p3 process-01.sim rr 4
A A A B B B B C C C C D D D D B B E E D
Name Fnsh T_r T_r/T_s
----------------------
A 3 3 1
B 17 15 2.5
C 11 7 1.75
D 20 14 2.8
E 19 11 5.5
Here we are running the simulation using the set of process
information given in the previous section
and with a time slice quantum of 4.
Required Output
As shown above, your program must generate 2 bits of output.
First of all, while running the simulation
of the selected scheduling policy, you should display the
process names in the order they are run. In
the previous example, the sequence of scheduled/run processes
was:
A A A B B B B C C C C D D D D B B E E D
This indicates that process A ran �rst (times 0, 1 and 2),
followed by B running 4 times (times 3
to 7), etc. You are required to output the sequence of process
runs as the �rst line of output, with a
single space in between each process name as shown.
After the processes have run, you need to calculate and display
the statistics for the processes that
you just simulated. In our previous example, the statistics for
our round-robin simulation with a time
quantum of 4 time slices were:
Name Fnsh T_r T_r/T_s
----------------------
A 3 3 1
B 17 15 2.5
C 11 7 1.75
2
D 20 14 2.8
E 19 11 5.5
For each process, you need to output the time when it �nished,
the turnaround time (Tr) and the
ratio of the turnaround time to the service time (Tr/Ts).
I have provided a zip �le with a �le named p3-start.cpp as a
template to get you started. In addition,
I have provided you with two process simulation �les, named
process-01.sim and process-02.sim, with
2 sets of process information you can simulate. There are
several examples of correct results generated
for the two sets of inputs, named things like process-01-q1.res,
process-01-q4.res, process-01-srt.res, etc.
These are the correct results you should get for running your
simulation with round-robin scheduling
for various time quantums or for shortest remaining time
scheduling.
3
processtable-01.sim
A 0 3
B 2 6
C 4 4
D 6 5
E 8 2
processtable-02.sim
A 0 4
B 1 7
C 4 5
D 4 5
E 7 2
F 8 5
G 10 1
H 10 4
I 12 6
processtable-03.sim
A 0 3
B 2 4
C 3 5
D 3 8
E 3 2
F 5 6
G 7 9
H 7 4
I 8 3
J 8 5
K 8 4
L 10 6
Makefile
all: p5sol
p5: p5-start.cpp
g++ -g $< -o [email protected]
p5sol: p5-solution.cpp
g++ -g $< -o p5
debug: p5-solution.cpp
g++ -DDEBUG_BUILD=1 -g $< -o p5
p5test:
./p5 processtable-01.sim rr 1 > sim-01-rr-1.tst
@diff -s -q sim-01-rr-1.tst sim-01-rr-1.res
./p5 processtable-01.sim rr 4 > sim-01-rr-4.tst
@diff -s -q sim-01-rr-4.tst sim-01-rr-4.res
./p5 processtable-01.sim srt > sim-01-srt.tst
@diff -s -q sim-01-srt.tst sim-01-srt.res
./p5 processtable-02.sim rr 1 > sim-02-rr-1.tst
@diff -s -q sim-02-rr-1.tst sim-02-rr-1.res
./p5 processtable-02.sim rr 4 > sim-02-rr-4.tst
@diff -s -q sim-02-rr-4.tst sim-02-rr-4.res
./p5 processtable-02.sim srt > sim-02-srt.tst
@diff -s -q sim-02-srt.tst sim-02-srt.res
./p5 processtable-03.sim rr 1 > sim-03-rr-1.tst
@diff -s -q sim-03-rr-1.tst sim-03-rr-1.res
./p5 processtable-03.sim rr 5 > sim-03-rr-5.tst
@diff -s -q sim-03-rr-5.tst sim-03-rr-5.res
./p5 processtable-03.sim srt > sim-03-srt.tst
@diff -s -q sim-03-srt.tst sim-03-srt.res
@rm sim-01-rr-1.tst sim-01-rr-4.tst sim-01-srt.tst sim-02-
rr-1.tst sim-02-rr-4.tst sim-02-srt.tst sim-03-rr-1.tst sim-03-rr-
5.tst sim-03-srt.tst
p5zip:
zip ../prog-05.zip p5-start.cpp prog-05.pdf processtable-
01.sim processtable-02.sim processtable-03.sim Makefile *.res
p5solzip:
zip ../prog-05-sol.zip p5-solution.cpp processtable-*.sim
sim-*.res
clean:
rm -f p5 sim-*.tst core* *~
sim-01-rr-1.res
sim-01-rr-4.res
sim-01-srt.res
sim-02-rr-1.res
sim-02-rr-4.res
sim-02-srt.res
sim-03-rr-1.res
sim-03-rr-5.res
sim-03-srt.res
p2-start.cppp2-start.cpp/**
* @author Your Name Here
* @cwid 123 45 678
* @class CSci 430, Summer 2017
* @ide Visual Studio Express 2017
* @date June 11, 2017
* @assg Programming Assignment #2
*
* @description Implement a simulation of a basic 3 process sta
te system
* Ready, Running, Blocked. Simulation includes a round-
robin scheduler
* with time slice scheduling. Need to implement a basic Proc
ess
* Control Block (PCB) in order to implement the round robin
scheduler.
* Program will also have ready queues, and possible queues o
r other
* structures to keep track of blocked processes and the events
they
* are waiting on.
*
*/
#include<stdlib.h>
#include<iostream>
#include<fstream>
#include<string>
usingnamespace std;
/** The process simulator.
* The main loop for running a simulation. We read simulation
* events from a file
*
* @param simfilename The name of the file (e.g. simulaiton-
01.sim) to open
* and read simulated event sequence from.
* @param timeSliceQuantum The value to be used for system ti
me slicing preemption
* for this simulation.
*/
void runSimulation(char* simfilename,int timeSliceQuantum)
{
ifstream simeventsfile(simfilename);
string command;
int eventnum;
if(!simeventsfile.is_open())
{
cout <<"Error: could not open simulator events file: "<< simf
ilename << endl;
exit(1);
}
while(!simeventsfile.eof())
{
simeventsfile >> command;
// Handle the next simulated event we just read from the
// simulation event file
if(command =="cpu")
{
cout <<" cpu: simulate a cpu cycle here"<< endl;
}
elseif(command =="new")
{
cout <<" new: simulate creation of new process here"<< e
ndl;
}
elseif(command =="done")
{
cout <<" done: simulate termination of currently running p
rocess here"<< endl;
}
elseif(command =="wait")
{
simeventsfile >> eventnum;
cout <<" wait: eventnum: "<< eventnum <<
" simulate event blocked and waiting"<< endl;
}
elseif(command =="event")
{
simeventsfile >> eventnum;
cout <<" event: eventnum: "<< eventnum <<
" simulate event occurring possibly making some processes read
y"<< endl;
}
elseif(command =="exit")
{
// we use an explicit indicator to ensure simulation exits correctl
y
break;
}
else
{
cout <<" ERROR: unknown command: "<< command << e
ndl;
exit(0);
}
}
simeventsfile.close();
}
/** Main entry point of simulator
* The main entry point of the process simulator. We simply se
t up
* and initialize the environment, then call the appropriate func
tion
* to begin the simulation. We expect a single command line ar
gument
* which is the name of the simulation event file to process.
*
* @param argc The argument count
* @param argv The command line argument values. We expect
argv[1] to be the
* name of a file in the current directory holding proces
s events
* to simulate.
*/
int main(int argc,char** argv)
{
int timeSliceQuantum =0;
// validate command line arguments
if(argc !=3)
{
cout <<"Error: expecting event file as first command line par
ameter and time slice quantum as second"<< endl;
cout <<"Usage: "<< argv[0]<<" simeventfile.sim time_slice"
<< endl;
exit(1);
}
// Assume second command line argument is the time slice quan
tum and parse it
timeSliceQuantum = atoi(argv[2]);
if(timeSliceQuantum <=0)
{
cout <<"Error: invalid time slice quantum received: "<< time
SliceQuantum << endl;
exit(1);
}
// Invoke the function to actually run the simulation
runSimulation(argv[1], timeSliceQuantum);
// if don't want to use command line do following.
// need to recompile by hand since file
// name to get simulated events from is hard coded
//runSimulation("simulation-01.sim", 5);
return0;
}
p2-start.c
/**
* @author Your Name Here
* @cwid 123 45 678
* @class CSci 430, Summer 2017
* @ide Visual Studio Express 2017
* @date June 11, 2017
* @assg Programming Assignment #2
*
* @description Implement a simulation of a basic 3 process
state system
* Ready, Running, Blocked. Simulation includes a round-
robin scheduler
* with time slice scheduling. Need to implement a basic
Process
* Control Block (PCB) in order to implement the round robin
scheduler.
* Program will also have ready queues, and possible queues
or other
* structures to keep track of blocked processes and the events
they
* are waiting on.
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/** The process simulator.
* The main loop for running a simulation. We read simulation
* events from a file
*
* @param simfilename The name of the file (e.g. simulaiton-
01.sim) to open
* and read simulated event sequence from.
* @param timeSliceQuantum The value to be used for system
time slicing preemption
* for this simulation.
*/
void runSimulation(char* simfilename, int timeSliceQuantum)
{
FILE* simeventsfile;
char line[256]; // temporary buffer to hold the whole line we
read in
char* command;
char* eventnumstr;
int eventnum;
// open the simulation file, and make sure we were successful
// before continuing
simeventsfile = fopen(simfilename, "r");
if (!simeventsfile)
{
fprintf(stderr, "Error: could not open simulator events file:
%sn", simfilename);
exit(1);
}
while (fgets(line, sizeof(line), simeventsfile))
{
// get first token from line, up to first whitespace character,
put into command
command = strtok(line, " tn"); // splits line on space, tab or
newline
// Handle the next simulated event we just read from the
// simulation event file
if (strcmp(command, "cpu") == 0)
{
printf(" cpu: simulate a cpu cycle heren");
}
else if (strcmp(command, "new") == 0)
{
printf(" new: simulate creation of a new process heren");
}
else if (strcmp(command, "done") == 0)
{
printf(" done: simulate termination of currently running
process heren");
}
else if (strcmp(command, "wait") == 0)
{
eventnumstr = strtok(NULL, " tn"); // get pointer to event
number string
sscanf(eventnumstr, "%d", &eventnum);
printf(" wait: eventnum: %d simulate event blocked and
waitingn", eventnum);
}
else if (strcmp(command, "event") == 0)
{
eventnumstr = strtok(NULL, " tn"); // get pointer to event
number string
sscanf(eventnumstr, "%d", &eventnum);
printf(" event: eventnum: %d simulate event occurring
possibly making some processes readyn", eventnum);
}
else if (strcmp(command, "exit") == 0)
{
// we use an explicit indicator to ensure simulation exits
correctly
break;
}
else
{
fprintf(stderr, "Error: unknown command: %sn",
command);
exit(0);
}
}
fclose(simeventsfile);
}
/** Main entry point of simulator
* The main entry point of the process simulator. We simply
set up
* and initialize the environment, then call the appropriate
function
* to begin the simulation. We expect a single command line
argument
* which is the name of the simulation event file to process.
*
* @param argc The argument count
* @param argv The command line argument values. We expect
argv[1] to be the
* name of a file in the current directory holding
process events
* to simulate.
*/
int main(int argc, char** argv)
{
int timeSliceQuantum = 0;
// validate command line arguments
if (argc != 3)
{
printf("Error: expecting event file as first command line
parameter and time slice quantum as secondn");
printf("Usage: %s simeventfile.sim time_slicen", argv[0]);
exit(1);
}
// Assume second command line argument is the time slice
quantum and parse it
timeSliceQuantum = atoi(argv[2]);
if (timeSliceQuantum <= 0)
{
printf("Error: invalid time slice quantum received: %dn",
timeSliceQuantum);
exit(1);
}
// Invoke the function to actually run the simulation
runSimulation(argv[1], timeSliceQuantum);
// if don't want to use command line do following.
// need to recompile by hand since file
// name to get simulated events from is hard coded
//runSimulation("simulation-01.sim", 5);
return 0;
}
prog-02.pdf
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
�le. The input describes a time sequence of events that occur.
These are the
full set of events you will simulate:
1
Event Description
cpu 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 �nished
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 �le 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:
2
� De�ne a simple process control block (PCB) to hold
information about
all processes currently running in your system. The PCB can be
a
simple C struct or a C++ class. At a minimum you need to have
a
�eld for the process identi�er 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.
Whenever
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 �lling 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 identi�er. The process identi�er 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
3
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 �nishing 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):
4
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):
5
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):
6
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 di� and your program is generating the correct
output, then
there will be no di�erence 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 queues. Note that
the queues
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 �rst process listed from the ready queue in the previous
system cycle.
I have given you some template code (p2-start.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 �le 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 �gure out how to invoke running it from the command
line, you
can change the line in 'p2-start.cpp' to explicitly run a particular
simulation
�le, like this:
runSimulation("simulation-01.sim", time_slice_quantum)
7
However, you need to make sure that your program correctly
works using
the command line invocation, as shown in `p2-start.cpp`.
I have given some template code to get you started in the �le
called
p2-start.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 �le events. Your job is to implement
the necessary
actions and data structures to handle the simulated events
described. The
runSimulation() in 'p2-start.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 �les you create for you solution (.c or .cpp/.c++ and
.h header
�les) should be uploaded to the MyLeo Online submission
folder created for
this assignment by the deadline. You should not attach any �les
besides the
source �les containing your C/C++ code. But you should make
sure you
attach all needed �les 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 �ne, 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 speci�c 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 class, if you would like an example implementation in plain
C that might
be simpler to use than learning the STL.
8
http://en.cppreference.com/w/
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
simulation-01.res
simulation-02.sim
new
cpu
new
cpu
new
cpu
cpu
cpu
cpu
cpu
wait 2
cpu
cpu
wait 1
cpu
event 2
event 1
cpu
cpu
cpu
cpu
cpu
cpu
cpu
done
cpu
cpu
cpu
done
cpu
cpu
done
exit
simulation-02.res
simulation-03.sim
new
cpu
cpu
cpu
new
new
new
cpu
cpu
cpu
cpu
wait 1
cpu
wait 1
cpu
cpu
wait 1
cpu
new
new
cpu
cpu
cpu
event 1
cpu
cpu
cpu
cpu
cpu
cpu
cpu
new
new
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
wait 1
cpu
cpu
wait 2
cpu
cpu
cpu
wait 3
cpu
cpu
event 2
cpu
cpu
cpu
cpu
wait 2
cpu
cpu
cpu
event 1
cpu
cpu
event 3
cpu
cpu
cpu
cpu
cpu
done
cpu
cpu
cpu
cpu
done
event 2
cpu
cpu
cpu
wait 1
cpu
cpu
cpu
cpu
cpu
done
cpu
done
event 1
cpu
cpu
done
cpu
cpu
exit
simulation-03.res
simulation-04.sim
new
new
cpu
cpu
cpu
cpu
done
new
cpu
cpu
cpu
cpu
wait 1
cpu
done
cpu
wait 1
cpu
cpu
new
new
cpu
cpu
event 1
done
cpu
cpu
cpu
cpu
done
cpu
cpu
done
cpu
cpu
new
new
cpu
cpu
wait 3
cpu
done
new
new
new
cpu
wait 4
cpu
event 3
cpu
done
new
cpu
cpu
cpu
event 4
cpu
cpu
cpu
done
cpu
cpu
cpu
cpu
cpu
cpu
done
cpu
cpu
done
cpu
exit
simulation-04.res
simulation-05.sim
new
new
new
new
new
new
cpu
cpu
done
cpu
cpu
done
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
wait 1
cpu
wait 1
cpu
wait 1
cpu
wait 1
cpu
wait 1
cpu
wait 1
cpu
wait 1
cpu
event 1
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
cpu
simulation-05-quantum5.res
simulation-05-quantum8.res

More Related Content

Similar to HS2021 Database Design and UseWeek 2 - 2020 Tutorial.docx

Deep Dive into Salesforce Integrations: Mapping Engines
Deep Dive into Salesforce Integrations:  Mapping EnginesDeep Dive into Salesforce Integrations:  Mapping Engines
Deep Dive into Salesforce Integrations: Mapping EnginesCRMScienceKirk
 
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docxMSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docxgilpinleeanna
 
Overview of query evaluation
Overview of query evaluationOverview of query evaluation
Overview of query evaluationavniS
 
Oracle_Analytical_function.pdf
Oracle_Analytical_function.pdfOracle_Analytical_function.pdf
Oracle_Analytical_function.pdfKalyankumarVenkat1
 
Data Flow Diagram (DFD) TipsProcesses VerbsDataflows N.docx
Data Flow Diagram (DFD) TipsProcesses VerbsDataflows N.docxData Flow Diagram (DFD) TipsProcesses VerbsDataflows N.docx
Data Flow Diagram (DFD) TipsProcesses VerbsDataflows N.docxwhittemorelucilla
 
SECTION D2)Display the item number and total cost for each order l.docx
SECTION D2)Display the item number and total cost for each order l.docxSECTION D2)Display the item number and total cost for each order l.docx
SECTION D2)Display the item number and total cost for each order l.docxkenjordan97598
 
Murach : How to work with session state and cookies
Murach : How to work with session state and cookiesMurach : How to work with session state and cookies
Murach : How to work with session state and cookiesMahmoudOHassouna
 
The ultimate-guide-to-sql
The ultimate-guide-to-sqlThe ultimate-guide-to-sql
The ultimate-guide-to-sqlMcNamaraChiwaye
 
Get started with R lang
Get started with R langGet started with R lang
Get started with R langsenthil0809
 
ADBMS ASSIGNMENT
ADBMS ASSIGNMENTADBMS ASSIGNMENT
ADBMS ASSIGNMENTLori Moore
 
Php and MySQL Web Development
Php and MySQL Web DevelopmentPhp and MySQL Web Development
Php and MySQL Web Developmentw3ondemand
 
Sql storeprocedure
Sql storeprocedureSql storeprocedure
Sql storeprocedureftz 420
 
Please the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdfPlease the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdfadmin463580
 
Pega Mock questions
Pega Mock questionsPega Mock questions
Pega Mock questionsAshock Roy
 
QTP Automation Testing Tutorial 7
QTP Automation Testing Tutorial 7QTP Automation Testing Tutorial 7
QTP Automation Testing Tutorial 7Akash Tyagi
 
Final report mobile shop
Final report   mobile shopFinal report   mobile shop
Final report mobile shopViditsingh22
 
This is the assignmentOBJECTIVESAfter finishing this lab, stude.pdf
This is the assignmentOBJECTIVESAfter finishing this lab, stude.pdfThis is the assignmentOBJECTIVESAfter finishing this lab, stude.pdf
This is the assignmentOBJECTIVESAfter finishing this lab, stude.pdfbharatchawla141
 

Similar to HS2021 Database Design and UseWeek 2 - 2020 Tutorial.docx (20)

xml rpc
xml rpcxml rpc
xml rpc
 
Deep Dive into Salesforce Integrations: Mapping Engines
Deep Dive into Salesforce Integrations:  Mapping EnginesDeep Dive into Salesforce Integrations:  Mapping Engines
Deep Dive into Salesforce Integrations: Mapping Engines
 
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docxMSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
 
Overview of query evaluation
Overview of query evaluationOverview of query evaluation
Overview of query evaluation
 
Oracle_Analytical_function.pdf
Oracle_Analytical_function.pdfOracle_Analytical_function.pdf
Oracle_Analytical_function.pdf
 
Data Flow Diagram (DFD) TipsProcesses VerbsDataflows N.docx
Data Flow Diagram (DFD) TipsProcesses VerbsDataflows N.docxData Flow Diagram (DFD) TipsProcesses VerbsDataflows N.docx
Data Flow Diagram (DFD) TipsProcesses VerbsDataflows N.docx
 
SECTION D2)Display the item number and total cost for each order l.docx
SECTION D2)Display the item number and total cost for each order l.docxSECTION D2)Display the item number and total cost for each order l.docx
SECTION D2)Display the item number and total cost for each order l.docx
 
Murach : How to work with session state and cookies
Murach : How to work with session state and cookiesMurach : How to work with session state and cookies
Murach : How to work with session state and cookies
 
The ultimate-guide-to-sql
The ultimate-guide-to-sqlThe ultimate-guide-to-sql
The ultimate-guide-to-sql
 
chapter_5_5.ppt
chapter_5_5.pptchapter_5_5.ppt
chapter_5_5.ppt
 
Get started with R lang
Get started with R langGet started with R lang
Get started with R lang
 
ch3
ch3ch3
ch3
 
ADBMS ASSIGNMENT
ADBMS ASSIGNMENTADBMS ASSIGNMENT
ADBMS ASSIGNMENT
 
Php and MySQL Web Development
Php and MySQL Web DevelopmentPhp and MySQL Web Development
Php and MySQL Web Development
 
Sql storeprocedure
Sql storeprocedureSql storeprocedure
Sql storeprocedure
 
Please the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdfPlease the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdf
 
Pega Mock questions
Pega Mock questionsPega Mock questions
Pega Mock questions
 
QTP Automation Testing Tutorial 7
QTP Automation Testing Tutorial 7QTP Automation Testing Tutorial 7
QTP Automation Testing Tutorial 7
 
Final report mobile shop
Final report   mobile shopFinal report   mobile shop
Final report mobile shop
 
This is the assignmentOBJECTIVESAfter finishing this lab, stude.pdf
This is the assignmentOBJECTIVESAfter finishing this lab, stude.pdfThis is the assignmentOBJECTIVESAfter finishing this lab, stude.pdf
This is the assignmentOBJECTIVESAfter finishing this lab, stude.pdf
 

More from ShiraPrater50

Read Chapter 3. Answer the following questions1.Wha.docx
Read Chapter 3. Answer the following questions1.Wha.docxRead Chapter 3. Answer the following questions1.Wha.docx
Read Chapter 3. Answer the following questions1.Wha.docxShiraPrater50
 
Read Chapter 15 and answer the following questions 1.  De.docx
Read Chapter 15 and answer the following questions 1.  De.docxRead Chapter 15 and answer the following questions 1.  De.docx
Read Chapter 15 and answer the following questions 1.  De.docxShiraPrater50
 
Read Chapter 2 and answer the following questions1.  List .docx
Read Chapter 2 and answer the following questions1.  List .docxRead Chapter 2 and answer the following questions1.  List .docx
Read Chapter 2 and answer the following questions1.  List .docxShiraPrater50
 
Read chapter 7 and write the book report  The paper should be .docx
Read chapter 7 and write the book report  The paper should be .docxRead chapter 7 and write the book report  The paper should be .docx
Read chapter 7 and write the book report  The paper should be .docxShiraPrater50
 
Read Chapter 7 and answer the following questions1.  What a.docx
Read Chapter 7 and answer the following questions1.  What a.docxRead Chapter 7 and answer the following questions1.  What a.docx
Read Chapter 7 and answer the following questions1.  What a.docxShiraPrater50
 
Read chapter 14, 15 and 18 of the class textbook.Saucier.docx
Read chapter 14, 15 and 18 of the class textbook.Saucier.docxRead chapter 14, 15 and 18 of the class textbook.Saucier.docx
Read chapter 14, 15 and 18 of the class textbook.Saucier.docxShiraPrater50
 
Read Chapter 10 APA FORMAT1. In the last century, what historica.docx
Read Chapter 10 APA FORMAT1. In the last century, what historica.docxRead Chapter 10 APA FORMAT1. In the last century, what historica.docx
Read Chapter 10 APA FORMAT1. In the last century, what historica.docxShiraPrater50
 
Read chapter 7 and write the book report  The paper should b.docx
Read chapter 7 and write the book report  The paper should b.docxRead chapter 7 and write the book report  The paper should b.docx
Read chapter 7 and write the book report  The paper should b.docxShiraPrater50
 
Read Chapter 14 and answer the following questions1.  Explain t.docx
Read Chapter 14 and answer the following questions1.  Explain t.docxRead Chapter 14 and answer the following questions1.  Explain t.docx
Read Chapter 14 and answer the following questions1.  Explain t.docxShiraPrater50
 
Read Chapter 2 first. Then come to this assignment.The first t.docx
Read Chapter 2 first. Then come to this assignment.The first t.docxRead Chapter 2 first. Then come to this assignment.The first t.docx
Read Chapter 2 first. Then come to this assignment.The first t.docxShiraPrater50
 
Journal of Public Affairs Education 515Teaching Grammar a.docx
 Journal of Public Affairs Education 515Teaching Grammar a.docx Journal of Public Affairs Education 515Teaching Grammar a.docx
Journal of Public Affairs Education 515Teaching Grammar a.docxShiraPrater50
 
Learner Guide TLIR5014 Manage suppliers TLIR.docx
 Learner Guide TLIR5014 Manage suppliers TLIR.docx Learner Guide TLIR5014 Manage suppliers TLIR.docx
Learner Guide TLIR5014 Manage suppliers TLIR.docxShiraPrater50
 
Lab 5 Nessus Vulnerability Scan Report © 2012 by Jone.docx
 Lab 5 Nessus Vulnerability Scan Report © 2012 by Jone.docx Lab 5 Nessus Vulnerability Scan Report © 2012 by Jone.docx
Lab 5 Nessus Vulnerability Scan Report © 2012 by Jone.docxShiraPrater50
 
Leveled and Exclusionary Tracking English Learners Acce.docx
 Leveled and Exclusionary Tracking English Learners Acce.docx Leveled and Exclusionary Tracking English Learners Acce.docx
Leveled and Exclusionary Tracking English Learners Acce.docxShiraPrater50
 
Lab 5 Nessus Vulnerability Scan Report © 2015 by Jone.docx
 Lab 5 Nessus Vulnerability Scan Report © 2015 by Jone.docx Lab 5 Nessus Vulnerability Scan Report © 2015 by Jone.docx
Lab 5 Nessus Vulnerability Scan Report © 2015 by Jone.docxShiraPrater50
 
MBA 6941, Managing Project Teams 1 Course Learning Ou.docx
 MBA 6941, Managing Project Teams 1 Course Learning Ou.docx MBA 6941, Managing Project Teams 1 Course Learning Ou.docx
MBA 6941, Managing Project Teams 1 Course Learning Ou.docxShiraPrater50
 
Inventory Decisions in Dells Supply ChainAuthor(s) Ro.docx
 Inventory Decisions in Dells Supply ChainAuthor(s) Ro.docx Inventory Decisions in Dells Supply ChainAuthor(s) Ro.docx
Inventory Decisions in Dells Supply ChainAuthor(s) Ro.docxShiraPrater50
 
It’s Your Choice 10 – Clear Values 2nd Chain Link- Trade-offs .docx
 It’s Your Choice 10 – Clear Values 2nd Chain Link- Trade-offs .docx It’s Your Choice 10 – Clear Values 2nd Chain Link- Trade-offs .docx
It’s Your Choice 10 – Clear Values 2nd Chain Link- Trade-offs .docxShiraPrater50
 
MBA 5101, Strategic Management and Business Policy 1 .docx
 MBA 5101, Strategic Management and Business Policy 1 .docx MBA 5101, Strategic Management and Business Policy 1 .docx
MBA 5101, Strategic Management and Business Policy 1 .docxShiraPrater50
 
MAJOR WORLD RELIGIONSJudaismJudaism (began .docx
 MAJOR WORLD RELIGIONSJudaismJudaism (began .docx MAJOR WORLD RELIGIONSJudaismJudaism (began .docx
MAJOR WORLD RELIGIONSJudaismJudaism (began .docxShiraPrater50
 

More from ShiraPrater50 (20)

Read Chapter 3. Answer the following questions1.Wha.docx
Read Chapter 3. Answer the following questions1.Wha.docxRead Chapter 3. Answer the following questions1.Wha.docx
Read Chapter 3. Answer the following questions1.Wha.docx
 
Read Chapter 15 and answer the following questions 1.  De.docx
Read Chapter 15 and answer the following questions 1.  De.docxRead Chapter 15 and answer the following questions 1.  De.docx
Read Chapter 15 and answer the following questions 1.  De.docx
 
Read Chapter 2 and answer the following questions1.  List .docx
Read Chapter 2 and answer the following questions1.  List .docxRead Chapter 2 and answer the following questions1.  List .docx
Read Chapter 2 and answer the following questions1.  List .docx
 
Read chapter 7 and write the book report  The paper should be .docx
Read chapter 7 and write the book report  The paper should be .docxRead chapter 7 and write the book report  The paper should be .docx
Read chapter 7 and write the book report  The paper should be .docx
 
Read Chapter 7 and answer the following questions1.  What a.docx
Read Chapter 7 and answer the following questions1.  What a.docxRead Chapter 7 and answer the following questions1.  What a.docx
Read Chapter 7 and answer the following questions1.  What a.docx
 
Read chapter 14, 15 and 18 of the class textbook.Saucier.docx
Read chapter 14, 15 and 18 of the class textbook.Saucier.docxRead chapter 14, 15 and 18 of the class textbook.Saucier.docx
Read chapter 14, 15 and 18 of the class textbook.Saucier.docx
 
Read Chapter 10 APA FORMAT1. In the last century, what historica.docx
Read Chapter 10 APA FORMAT1. In the last century, what historica.docxRead Chapter 10 APA FORMAT1. In the last century, what historica.docx
Read Chapter 10 APA FORMAT1. In the last century, what historica.docx
 
Read chapter 7 and write the book report  The paper should b.docx
Read chapter 7 and write the book report  The paper should b.docxRead chapter 7 and write the book report  The paper should b.docx
Read chapter 7 and write the book report  The paper should b.docx
 
Read Chapter 14 and answer the following questions1.  Explain t.docx
Read Chapter 14 and answer the following questions1.  Explain t.docxRead Chapter 14 and answer the following questions1.  Explain t.docx
Read Chapter 14 and answer the following questions1.  Explain t.docx
 
Read Chapter 2 first. Then come to this assignment.The first t.docx
Read Chapter 2 first. Then come to this assignment.The first t.docxRead Chapter 2 first. Then come to this assignment.The first t.docx
Read Chapter 2 first. Then come to this assignment.The first t.docx
 
Journal of Public Affairs Education 515Teaching Grammar a.docx
 Journal of Public Affairs Education 515Teaching Grammar a.docx Journal of Public Affairs Education 515Teaching Grammar a.docx
Journal of Public Affairs Education 515Teaching Grammar a.docx
 
Learner Guide TLIR5014 Manage suppliers TLIR.docx
 Learner Guide TLIR5014 Manage suppliers TLIR.docx Learner Guide TLIR5014 Manage suppliers TLIR.docx
Learner Guide TLIR5014 Manage suppliers TLIR.docx
 
Lab 5 Nessus Vulnerability Scan Report © 2012 by Jone.docx
 Lab 5 Nessus Vulnerability Scan Report © 2012 by Jone.docx Lab 5 Nessus Vulnerability Scan Report © 2012 by Jone.docx
Lab 5 Nessus Vulnerability Scan Report © 2012 by Jone.docx
 
Leveled and Exclusionary Tracking English Learners Acce.docx
 Leveled and Exclusionary Tracking English Learners Acce.docx Leveled and Exclusionary Tracking English Learners Acce.docx
Leveled and Exclusionary Tracking English Learners Acce.docx
 
Lab 5 Nessus Vulnerability Scan Report © 2015 by Jone.docx
 Lab 5 Nessus Vulnerability Scan Report © 2015 by Jone.docx Lab 5 Nessus Vulnerability Scan Report © 2015 by Jone.docx
Lab 5 Nessus Vulnerability Scan Report © 2015 by Jone.docx
 
MBA 6941, Managing Project Teams 1 Course Learning Ou.docx
 MBA 6941, Managing Project Teams 1 Course Learning Ou.docx MBA 6941, Managing Project Teams 1 Course Learning Ou.docx
MBA 6941, Managing Project Teams 1 Course Learning Ou.docx
 
Inventory Decisions in Dells Supply ChainAuthor(s) Ro.docx
 Inventory Decisions in Dells Supply ChainAuthor(s) Ro.docx Inventory Decisions in Dells Supply ChainAuthor(s) Ro.docx
Inventory Decisions in Dells Supply ChainAuthor(s) Ro.docx
 
It’s Your Choice 10 – Clear Values 2nd Chain Link- Trade-offs .docx
 It’s Your Choice 10 – Clear Values 2nd Chain Link- Trade-offs .docx It’s Your Choice 10 – Clear Values 2nd Chain Link- Trade-offs .docx
It’s Your Choice 10 – Clear Values 2nd Chain Link- Trade-offs .docx
 
MBA 5101, Strategic Management and Business Policy 1 .docx
 MBA 5101, Strategic Management and Business Policy 1 .docx MBA 5101, Strategic Management and Business Policy 1 .docx
MBA 5101, Strategic Management and Business Policy 1 .docx
 
MAJOR WORLD RELIGIONSJudaismJudaism (began .docx
 MAJOR WORLD RELIGIONSJudaismJudaism (began .docx MAJOR WORLD RELIGIONSJudaismJudaism (began .docx
MAJOR WORLD RELIGIONSJudaismJudaism (began .docx
 

Recently uploaded

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 

Recently uploaded (20)

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 

HS2021 Database Design and UseWeek 2 - 2020 Tutorial.docx

  • 1. HS2021 Database Design and Use Week 2 - 2020 Tutorial Date: Instructions: This exam has three (3) questions. You are expected to select one question out of three (3) questions and to submit your answer via the blackboard assessment system. Assessment Weight: This test accounts for five per cent (5%) of total marks. Total marks for the paper 5 marks Question A: Create the Entity-Relationship Diagram and the Relational Schema for the following scenario BestBank prides itself on having up-to-date information on the current account balance of its customers. To do this, BestBank relies on a company-wide information system. Customers are the heart of the BestBank information system. Customers are characterized by their customer number (unique), first name, last name, address, and date of birth. A customer can have multiple accounts into the BestBank information system. Accounts are characterized by their account number (unique), account type (i.e. everyday, savings, business) and amount and they must be assigned to a specific customer. To keep track of their spending habits BestBank customers can review all the
  • 2. transactions executed using their accounts. A transaction must be associated with a specific account, and each account can have multiple transactions. Finally, each transaction is characterized by a transaction id (unique), a transaction type (i.e. withdraw or deposit) and the transaction amount. Question B: Create the Entity-Relationship Diagram and the Relational Schema for the following scenario BestDelivery prides itself on having up-to-date information on the status of shipped item. To do this, BestDelivery relies on a company-wide information system. Items are the heart of the BestDelivery information system. Items are characterized by their item code (unique), delivery status, and destination address. Items are assigned to couriers who are in charge of their delivery. A courier delivers several items in a day. Couriers are characterized by their employee number (unique), first name, last name, and driving license. Question C: Create the Entity-Relationship Diagram and the Relational Schema for the following scenario BestFreelancer prides itself on having the most efficient platform through which is possible to find freelancers for any type of work. Freelancers can freely register on the platform and provide information about all the projects they have completed. To do this, BestFreelancer relies on a company-wide information system. Freelancers are the heart of the BestFreelancer information system. Freelancers are characterized by their profile code (unique), first name, last name, and email. Freelancers can list, within their profile, as many projects as they want. Projects are characterized by their project code (unique), start date, end date, project title, and project description. Student Name: _____________________________________________________
  • 3. Student ID: ____________________________ HS2021 Database Design and use Week 2 - 2020 10 p3-start.cppp3-start.cpp/** @file p3-start.cpp * * @author Your Name Here * * @assg Programming Assignment #3 * * @desc Implement the deadlock detection algorithm. Given a file * that describes the current allocation A of resources in th e * system, and the current set of outstanding requests Q in * the system, determine if a deadlock is present or not. U se * the algorithm given on p.276 in the Stallings textbook. * * @date March 05, 2018 */ #include<stdlib.h> #include<iostream> #include<iomanip> #include<fstream> #include<string> usingnamespace std;
  • 4. // global constants constint MAX_PROCESSES =10;// I won't test your algorithm with simulations with more than 10 processes constint MAX_RESOURCES =10;// nor will I give a simulation to test with more than 10 resources // simple struct to read in and hold the state of the system typedefstruct { int numResources; int numProcesses; int available[MAX_RESOURCES];// V available vector int alloc[MAX_PROCESSES][MAX_RESOURCES];// A allocati on matrix int request[MAX_PROCESSES][MAX_RESOURCES];// Q requ est matrix }State; /** Read system state from file. * Given a file, read the current system state from the file. * The system state file is expected to hold the available vector V * the allocation matrix A and the request matrix Q. * * @param simfilename The name of the file to open and read st ate & request * from. * @return state A new State structure is allocated and filled wit h the * system state from the file. A pointer to this allocated sy stem * state structure is returned as a result of calling this func
  • 5. tion. */ State* readSystemState(char* statefilename) { ifstream simstatefile(statefilename); State* state; int r, p; // If we can't open file, abort and let the user know problem if(!simstatefile.is_open()) { cout <<"Error: could not open system state file: "<< statefile name << endl; exit(1); } // dynamically allocate a new State structure, to be filled in and returned state =newState; // Format of file is this (where m = numResource n = numProces ses // V = available vector // A = allocation matrix and // Q = request matrix) // m n // V1 V2 V3 ... Vm // A11 A12 ... A1m // ... // An1 An2 ... Anm // Q11 Q12 ... Q1m // ... // Qn1 Qn2 ... Qnm // First line, get m (numResources) and n (numProcesses)
  • 6. simstatefile >> state->numResources >> state->numProcesses; // Next line contains the available vector V for(r =0; r < state->numResources; r++) { simstatefile >> state->available[r]; } // Next n lines contain the allocation matrix A for(p =0; p < state->numProcesses; p++) { for(r =0; r < state->numResources; r++) { simstatefile >> state->alloc[p][r]; } } // Next n lines contain the request matrix Q for(p =0; p < state->numProcesses; p++) { for(r =0; r < state->numResources; r++) { simstatefile >> state->request[p][r]; } } // return the newly allocated and filled in system state return state; } /** Display a vector * Display a state vector to standard output * * @param len The number of items in the vector * @param v An array of integers of len items */
  • 7. void displayVector(int len,int v[]) { int i; // Display a header for(i =0; i < len; i++) { cout <<"R"<< i <<" "; } cout << endl; // Display values for(i =0; i < len; i++) { cout << setw(2)<< v[i]<<" "; } cout << endl; } /** Display a matrix * Display a state matrix to standard output * * @param rows The number of rows in the matrix * @param cols The number of cols in the matrix * @param m A 2 dimensional array of rows x cols integers */ void displayMatrix(int rows,int cols,int v[MAX_PROCESSES][ MAX_RESOURCES]) { int r, c; // display column headers cout <<" ";// extra space over for row labels for(c =0; c < cols; c++) { cout <<"R"<< c <<" ";
  • 8. } cout << endl; // now display data in matrix for(r =0; r < rows; r++) { cout <<"P"<< r <<" "; for(c =0; c < cols; c++) { cout << setw(2)<< v[r][c]<<" "; } cout << endl; } cout << endl; } /** Display state * Display the values of the resource vectors and matrices in the indicated * state structure * * @param state A pointer to a State struct whose info we shoul d display on stdout. */ void displayState(State* s) { cout <<"numResources (m) = "<< s->numResources <<" "; cout <<"numProcesses (n) = "<< s- >numProcesses << endl << endl; cout <<"Available vector V:"<< endl; displayVector(s->numResources, s->available); cout << endl; cout <<"Allocation matrix A: "<< endl; displayMatrix(s->numProcesses, s->numResources, s->alloc);
  • 9. cout << endl; cout <<"Request matrix Q: "<< endl; displayMatrix(s->numProcesses, s->numResources, s- >request); cout << endl; } /** The deadlock detector * The starting point for implementation of the deadlock detecti on algorithm. * We open and read in the allocation matrices here, then perfor m the deadlock detection. * * @ param statefilename A string with the name of the file hol ding the A and Q system state matrices */ void detectDeadlock(char* statefilename) { State* state; state = readSystemState(statefilename); // I have provided some example routines to read and display sy stem state, implemented as a plain // C struct using C 1 and 2 dimensional arrays. You can uncom ment out the following, and/or use // the displayMatrix() and displayVector() functions to help you debug. But make sure you // remove or comment back up any statements after you are done debugging. displayState(state); // You need to implement your solution here. I would recomme nd you use functions for each of
  • 10. // these steps. // Step 1: Set up a data structure that records marked/unmarked // processes. All processes are initially unmarked Search // through the allocation matrix to find rows of all 0, and // mark corresponding processes in your mark structure // Step 2: Create a temporary vector W. Copy contents of availa ble // vector V to W. Suggestion: create a function called // copyVector, that takes a vector as its parameter, and returns // a new vector. // Need to put Steps 3 and 4 in a loop // Step 3: Find index i such that process i is currently unmarked, // and the ith row of Q is less than or equal to W. If no // such process is found, need to terminate algorithm/loop. // Suggestion: write a function that takes Q and W, and // returns either i (index of process meeting criteria) or // -1 // Step 4: If a row was found (e.g. i was a valid process that met // criteria of step 3), mark process i and add the // correspoinding row of allocation matrix to W. Loop bac k // to beginning of step 3. // Step 5: after loop finishes, // if (your marked/unmarked processes contains unmarked proce sses) // { // cout << "Deadlock"; // // loop through your marked/unmarked structure, print out al l unmarked processes as P1, P2, etc. // cout << endl;
  • 11. // } // else // all processes were marked, so no deadlock // { // cout << "No Deadlock" << endl; // } } /** Main entry point of deadlock detection. * The main entry point of the deadlock detection program. Thi s function * checks the command line arguments, and calls the detection f unction if correct * arguments were supplied. We expect a single command line argument * which is the name of the file holding the allocation and reque st matrices * of the current state of the system. * * @param argc The argument count * @param argv The command line argument values. We expect argv[1] to be the * name of a file in the current directory holding A and Q matrices. */ int main(int argc,char** argv) { if(argc !=2) { cout <<"Error: expecting state matrix file as first command li ne parameter"<< endl; cout <<"Usage: "<< argv[0]<<" system-state.sim"<< endl; exit(1); } detectDeadlock(argv[1]);
  • 12. // if don't want to use command line do following. Need to reco mpile by hand since file // name to get simulated events from is hard coded. // Make sure you revert back to using command line before sub mitting your program. //detectDeadlock("state-01.sim"); } prog-03.pdf CSci 430: Programming Project #3 Deadlock Detection Spring 2019 Dates: Assigned: Monday February 25, 2019 Due: Wednesday March 13, 2019 (before Midnight) Objectives: � Learn more about Deadlock algorithms. � Better understand how we can algorithmically detect deadlocks on a system. � Use C/C++ to implement vector and matrix data structures, get prac- tice in creating and using such data structures in C/C++. Description:
  • 13. Our textbook gives the following algorithm (pg. 276) for algorithmically detecting if a deadlock is present or not in a system. It requires that the system keep an Allocation matrix A, listing which resources are currently allocated to which processes, and the available vector V, which gives the amount of each resource currently available in the system. In addition, the deadlock detection algorithm requies a request matrix Q, which keeps track of the amount of each resource each process is currently requesting from the system. The algorithm is: 1. Mark each process that has a row in the Allocation matrix of all zeros. 2. Initialize a temporary vector W to equal the Available vector A. 1 3. Find an index i such that process i is currently unmarked and the i th row of Q is less than or equal to W. That is, Qik ≤ Wk, for 1 ≤ k ≤ m. If no such row is found, terminate the algorithm. 4. If such a row is found, mark process i and add the corresponding row of the allocation matrix to W. That is, set Wk = Wk+Aik, for 1 ≤ k
  • 14. ≤ m. Return to step 3. A deadlock exists if and only if there are unmarked processes at the end of the algorithm. Each unmarked process is deadlocked. In this assignment we will implement the deadlock detection algorithm. Your program will be given a �le that describes the A allocation matrix and the Q request matrix, representing the current state of all allocations and requested allocations in the system. Your program will implement the deadlock detection algorithm described above. The result of your program will be one of 2 outputs: 1. If no deadlock exists, the program will display No Deadlock on stan- dard output. 2. If a deadlock does exist, the program will display Deadlock: P0, P1, P2 on standard output, where P0, P1, P2 are the processes that the algorithm determined to be deadlocked in the system. State simulation �le formats I have provided a p3-start.cpp template that can open up and read in the process/resource state simulation �les used for this assignment. Here we discuss a bit more the format of these �le. I have provided 2 or
  • 15. 3 exam- ple simulations, with expected correct answers, for you to use to test your implementations with. The input �les needed for this assignment need to contain the information found in the V available vector and the A allocation and Q request matrices. In the following I use r as the number of resources and p as the number of processes. Thus the general format of the input �le is: r p V1 V2 V3 ... Vr A11 A12 ... A1r ... Ap1 Ap2 ... Apr 2 Q11 Q12 ... Q1r ... Qp1 Qp2 ... Qpr For example, the example of the deadlock detection algorithm given on page 277 has a system with r=5 resources and p=4 processes.
  • 16. The V, A and Q vector/matrices are shown on that page. The input �le for the current state of the system shown on page 277 would be 5 4 0 0 0 0 1 1 0 1 1 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 1 0 0 0 0 1 1 0 1 0 1 The function named readSystemState() in your template p2- start.cpp code expects a �le of this format, and reads it into a State structure for you. Running Simulations The following is a discussion of the expected output of your program. Your program must work from the command line, and expect a single parameter,
  • 17. the name of the state simulation input �le, as its input. Your program should display only a single line to standard output as a result of running it. If the system, described in the state input �le is not deadlocked, the program should simply state there was no deadlock to standard output: $ p3.exe state-02.sim No Deadlock On the other hand, if your program is deadlocked, it should say that it detected a deadlock, and it should print out the processes that are deadloked to standard output: $ p3.exe state-01.sim Deadlock: P0, P1, 3 I have provided 2 or 3 example input state �les, named state- 01.sim, state-02.sim, etc. I have also provided the correct and expected output for these simulations, named state-01.res, state-02.out, etc. 4 state-01.sim
  • 18. 5 4 0 0 0 0 1 1 0 1 1 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 1 0 0 0 0 1 1 0 1 0 1 state-01.res state-02.sim 5 4 0 1 0 0 1 1 0 1 1 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 1 0 0 0 0 1 1 0 1 0 1 state-02.res state-03.sim 8 7 0 2 0 1 2 3 1 0 1 0 1 0 0 0 1 1 0 0 0 2 1 0 0 0
  • 19. 1 0 0 0 0 2 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 state-03.res state-04.sim 8 7 0 0 0 1 2 3 1 0 1 0 1 0 0 0 1 1 0 0 0 2 1 0 0 0 1 0 0 0 0 2 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 2 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0
  • 20. state-04.res state-05.sim 10 10 1 0 1 0 2 2 1 2 2 1 1 0 1 0 0 0 0 2 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 0 1 0 0 1 0 0 0 2 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 1 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 1 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 state-05.res state-06.sim 10 10 1 0 0 0 0 2 0 2 2 1
  • 21. 1 0 1 0 0 0 0 2 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 0 1 0 0 1 0 0 0 2 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 1 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 1 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 state-06.res state-07.sim 10 10 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 2 0 1 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  • 22. 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 1 0 0 0 0 1 0 1 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 2 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 state-07.res state-08.sim 10 10 0 1 1 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 2 0 1 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 1 0 0 0 0 1 0 1 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0
  • 23. 0 0 0 0 0 1 0 0 0 0 1 2 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 state-08.res p5-start.cppp5-start.cpp/** * @author Jane Student * @cwid 123 45 678 * @class CSci 430, Spring 2018 * @ide Visual Studio Express 2010 * @date November 15, 2018 * @assg prog-04 * * @description This program implements a simulation of proce ss * scheduling policies. In this program, we implement round- robin * scheduling, where the time slice quantum can be specified a s * as a command line parameter. And we also implement shor test * remaining time (SRT) scheduling policy */ #include<stdlib.h> #include<iostream> #include<iomanip> #include<fstream> #include<string> #include<list> usingnamespace std;
  • 24. // global constants // I won't test your round robin implementation with more than 2 0 processes constint MAX_PROCESSES =20; constint NO_PROCESS =0; // Simple structure, holds all of the information about processes, their names // arrival and service times, that we are to simulate. typedefstruct { string processName; int arrivalTime; int serviceTime; // holds running count of time slices for current time quantum, when // serviceTime == quantum, time slice is up int sliceTime; // holds total number of time steps currently run, when == to // serviceTime process is done int totalTime; // holds time when process finishes, used to calculate final stats, // like T_r, T_r/T_s int finishTime; // a boolean flag, we will set this to true when the process is co mplete bool finished; }Process; // Process table, holds table of information about processes we a re simulating typedefstruct { int numProcesses; Process* process[MAX_PROCESSES];
  • 25. }ProcessTable; /** Create process table * Allocate memory for a new process table. Load the process * information from the simulation file into a table with the proc ess * information needed to perform the simulation. At the same ti me we * initialize other information in process table for use in the * simulation. Return the newly created ProcessTable * * @param processFilanem The name (char*) of the file to open and read * the process information from. * @param processTable This is actually a return parameter. Th is * should be a pointer to an already allocated array of * Process structure items. We will fill in this structure * and return the process information. * * @returns ProcessTable* The newly allocated and initialized P rocessTable * structure. */ ProcessTable* createProcessTable(char* processFilename) { ifstream simprocessfile(processFilename); ProcessTable* processTable; int pid; string processName; int arrivalTime; int serviceTime; // If we can't open file, abort and let the user know problem if(!simprocessfile.is_open())
  • 26. { cout <<"Error: could not open process simulation file: " << processFilename << endl; exit(1); } // Format of file is // ProcessName1 ArrivalTime1 ServiceTime1 // ProcessName2 ArrivalTime2 ServiceTime2 // ... // ProcessNameN ArrivalTimeN ServiceTimeN // // Where the name is any arbitray string identifier, and ArrivalT ime // and ServiceTime are integer values pid =0; processTable =new(ProcessTable); while(simprocessfile >> processName >> arrivalTime >> servic eTime) { // allocate a new process to hold information Process* process =new(Process); processTable->process[pid]= process; // load information into process read from simulation file process->processName = processName; process->arrivalTime = arrivalTime; process->serviceTime = serviceTime; // initialize other process information for the simulaiton process->sliceTime =0; process->totalTime =0; process->finishTime =0; process->finished =false; pid++;
  • 27. } // Set the number of processes we need to simulate information i n // the process table processTable->numProcesses = pid; return processTable; } /** Display process table * Convenience method, dump all of the information about the p rocesses * in a process table to stdout. * * @param processTable The table, a pointer to type ProcessTab le * struct, with the information we are to display */ void displayProcessTable(ProcessTable* processTable) { cout <<"Process Table num = "<< processTable- >numProcesses << endl; cout <<"PID Name Arrv Srvc"<< endl; cout <<"------------------"<< endl; for(int pid=0; pid < processTable->numProcesses; pid++) { Process* p = processTable->process[pid]; cout << setw(2)<< right << pid <<") "; cout << setw(4)<< left << p->processName <<" "; cout << setw(4)<< right << p->arrivalTime <<" "; cout << setw(4)<< right << p->serviceTime <<" "; cout << endl; } }
  • 28. /** Round robin scheduler simulator * The main routine for performing the round robin preemptive * scheduler simulator. We expect the time quantum to already be * specified and given to us as the first parameter. The file nam e * with the process arrival and service time information is given as * the second parameter. We simulate preemptive round robin * scheduling of all of the processes until there are no longer an y * processes left in the system (all processes have exceeded thei r * service time and have exited). * * @param processTable A pointer to a ProcessTable structure h olding * information about the processes, arrival times and duratio ns * that we are simulating execution of. * @param quantum An integer value holding the time slice qua ntum we * are using for this simulation. */ void roundRobinScheduler(ProcessTable* processTable,int quan tum) { // Implement the round robin scheduler here cout <<"<roundRobinScheduler> entered, quantum: "<< quant um << endl; } /** shortest remaining time simulator
  • 29. * The main routine for performing the shortest remaining time * preemptive scheduler simulator. The file name with the proc ess * arrival and service time information is given as the first * parameter. We simulate preemptive shortest remaining time * scheduling of all of the processes until there are no longer an y * processes left in the system (all processes have exceeded thei r * service time and have exited). * * @param processTable A pointer to a ProcessTable structure h olding * information about the processes, arrival times and duratio ns * that we are simulating execution of. */ void shortestRemainingTime(ProcessTable* processTable) { // Implement the shortest remaining time policy here cout <<"<shortestRemainingTime> entered"<< endl; } /** Main entry point of round robin scheduler * The main entry point of the round robin scheduler simulator. The main funciton * checks the command line arguments, and calls the simulation function if correct * arguments were supplied. We expect two command line argu ments, which are the * time slice quantum value we are to use for this preemptive sc heduler simulation, * and the name of the simulation file holding the process arriva l and service * time information.
  • 30. * * @param argc The argument count * @param argv The command line argument values. We expect argv[1] to be the * time slice quantum parameter (int format) and argv[2 ] to be the * name of the process simulation file (charcter string) */ int main(int argc,char** argv) { string policy; ProcessTable* processTable; int quantum =0; // If not all parameters provides, abort and let user know of prob lem if(argc <3|| argc >4) { cout <<"Error: expecting process simulation file and scheduli ng policy as command line parameters" << endl; cout <<"Usage: "<< argv[0]<<" process- file.sim [rr|srt] [quantum]"<< endl; exit(1); } // load process table and parse command line arguments processTable = createProcessTable(argv[1]); // just to confirm that process table loaded correctly. You shoul d // comment out or remove this as it is not asked for as part of th e // output for the assignment simulation displayProcessTable(processTable); // determine policy to simulate
  • 31. policy.assign(argv[2]); // perform simulation of indicated scheduling policy if(policy =="rr") { if(argc !=4) { cout <<"Error: time quantum must be provided for round ro bin `rr` scheduling policy"<< endl; exit(1); } quantum = atoi(argv[3]); if((quantum <=0)||(quantum >1000)) { cout <<"Error: received bad time slice quantum parameter: "<< argv[1]<< endl; cout <<" valid values are integers in range from 1 to 10 00"<< endl; exit(1); } roundRobinScheduler(processTable, quantum); } elseif(policy =="srt") { shortestRemainingTime(processTable); } else { cout <<"Error: unknown process scheduling policy: "<< polic y << endl; } } prog-05.pdf
  • 32. Programming Assignment #5 CSci 430, Spring 2019 Dates: Assigned: Monday April 15, 2019 Due: Wednesday May 1, 2019 (before Midnight) Objectives: � Understand short-term process scheduling. � Work with data structures to implement a round-robin scheduler. � Look at e�ects of di�erent time slice quantum sizes on the round-robin scheduling algorithm. � Use C/C++ to implement vector and matrix data structures, get practice in creating and using such data structures in C/C++. Description: Our textbooks chapter 9 discusses several possible short-term process scheduling policies. In this programming assignment exercise we will implement two of the preemptive policies, the simple shortest remaining time policy (SRT) and the round-robin scheduler with preemptive time slicing. Your program will be given a simple input �le, indicating the process name, its arrival time and its total service time, the same as the process scheduling examples from our textbook
  • 33. in Table 9.4 and Figure 9.5. You will simulate the execution of the required schedulers. As in previous assignments, you program will need to work non-interactively and be callable from the command line. The program will be provided with the �le name of a �le with process information, in the format discussed below. Your program will also be given the time slicing quantum parameter it is to use for the simulation, if round-robin scheduling is selected. Your program will need to output the results of running the set of simulated processes using the selected scheduling policy with the indicated time slice for the round-robin scheduler. Your program will have to output its results exactly as shown below in the required output format. Your program will also need to calculate some summary statistics for the simulated processes, including the turnaround time and Tr/Ts ratio for each process, and the mean Tr and Tr/Ts values for the given simulation. Process simulation �le formats The �les with the information about the processes to be simulated are fairly simple, and have the same information that our textbook uses to illustrate the process scheduling examples. Each simulation �le contains multiple rows of data, where each row consists of the process name, its arrival time, and its service time. Here is an example: 1 A 0 3
  • 34. B 2 6 C 4 4 D 6 5 E 8 2 This �le is named process-01.sim in the zip archive of �les I have given you to get started on this assignment. This is also the same set of processes and start/service times used for all of the examples in table 9.4 and �gure 9.5. Running Simulations As with previous assignments you are required to support using your simulation from the command line. Your program will take the name of the �le containing the process information �rst. The next parameter will be either 'rr' to perform round-robin scheduling, or 'srt' if shortest remaining time policy is to be simulated. Finally, a 3rd parameter will be supplied for the round-robin scheduler, the time slice quantum to use. An example of running your �nished program should look like this: $ ./p3 process-01.sim rr 4 A A A B B B B C C C C D D D D B B E E D Name Fnsh T_r T_r/T_s ----------------------
  • 35. A 3 3 1 B 17 15 2.5 C 11 7 1.75 D 20 14 2.8 E 19 11 5.5 Here we are running the simulation using the set of process information given in the previous section and with a time slice quantum of 4. Required Output As shown above, your program must generate 2 bits of output. First of all, while running the simulation of the selected scheduling policy, you should display the process names in the order they are run. In the previous example, the sequence of scheduled/run processes was: A A A B B B B C C C C D D D D B B E E D This indicates that process A ran �rst (times 0, 1 and 2), followed by B running 4 times (times 3 to 7), etc. You are required to output the sequence of process runs as the �rst line of output, with a single space in between each process name as shown. After the processes have run, you need to calculate and display the statistics for the processes that you just simulated. In our previous example, the statistics for our round-robin simulation with a time quantum of 4 time slices were:
  • 36. Name Fnsh T_r T_r/T_s ---------------------- A 3 3 1 B 17 15 2.5 C 11 7 1.75 2 D 20 14 2.8 E 19 11 5.5 For each process, you need to output the time when it �nished, the turnaround time (Tr) and the ratio of the turnaround time to the service time (Tr/Ts). I have provided a zip �le with a �le named p3-start.cpp as a template to get you started. In addition, I have provided you with two process simulation �les, named process-01.sim and process-02.sim, with 2 sets of process information you can simulate. There are several examples of correct results generated for the two sets of inputs, named things like process-01-q1.res, process-01-q4.res, process-01-srt.res, etc. These are the correct results you should get for running your simulation with round-robin scheduling for various time quantums or for shortest remaining time scheduling.
  • 37. 3 processtable-01.sim A 0 3 B 2 6 C 4 4 D 6 5 E 8 2 processtable-02.sim A 0 4 B 1 7 C 4 5 D 4 5 E 7 2 F 8 5 G 10 1 H 10 4 I 12 6 processtable-03.sim A 0 3 B 2 4 C 3 5 D 3 8 E 3 2 F 5 6 G 7 9 H 7 4 I 8 3 J 8 5 K 8 4
  • 38. L 10 6 Makefile all: p5sol p5: p5-start.cpp g++ -g $< -o [email protected] p5sol: p5-solution.cpp g++ -g $< -o p5 debug: p5-solution.cpp g++ -DDEBUG_BUILD=1 -g $< -o p5 p5test: ./p5 processtable-01.sim rr 1 > sim-01-rr-1.tst @diff -s -q sim-01-rr-1.tst sim-01-rr-1.res ./p5 processtable-01.sim rr 4 > sim-01-rr-4.tst @diff -s -q sim-01-rr-4.tst sim-01-rr-4.res ./p5 processtable-01.sim srt > sim-01-srt.tst @diff -s -q sim-01-srt.tst sim-01-srt.res ./p5 processtable-02.sim rr 1 > sim-02-rr-1.tst @diff -s -q sim-02-rr-1.tst sim-02-rr-1.res ./p5 processtable-02.sim rr 4 > sim-02-rr-4.tst @diff -s -q sim-02-rr-4.tst sim-02-rr-4.res ./p5 processtable-02.sim srt > sim-02-srt.tst @diff -s -q sim-02-srt.tst sim-02-srt.res ./p5 processtable-03.sim rr 1 > sim-03-rr-1.tst @diff -s -q sim-03-rr-1.tst sim-03-rr-1.res ./p5 processtable-03.sim rr 5 > sim-03-rr-5.tst @diff -s -q sim-03-rr-5.tst sim-03-rr-5.res ./p5 processtable-03.sim srt > sim-03-srt.tst @diff -s -q sim-03-srt.tst sim-03-srt.res
  • 39. @rm sim-01-rr-1.tst sim-01-rr-4.tst sim-01-srt.tst sim-02- rr-1.tst sim-02-rr-4.tst sim-02-srt.tst sim-03-rr-1.tst sim-03-rr- 5.tst sim-03-srt.tst p5zip: zip ../prog-05.zip p5-start.cpp prog-05.pdf processtable- 01.sim processtable-02.sim processtable-03.sim Makefile *.res p5solzip: zip ../prog-05-sol.zip p5-solution.cpp processtable-*.sim sim-*.res clean: rm -f p5 sim-*.tst core* *~ sim-01-rr-1.res sim-01-rr-4.res sim-01-srt.res sim-02-rr-1.res sim-02-rr-4.res sim-02-srt.res sim-03-rr-1.res
  • 40. sim-03-rr-5.res sim-03-srt.res p2-start.cppp2-start.cpp/** * @author Your Name Here * @cwid 123 45 678 * @class CSci 430, Summer 2017 * @ide Visual Studio Express 2017 * @date June 11, 2017 * @assg Programming Assignment #2 * * @description Implement a simulation of a basic 3 process sta te system * Ready, Running, Blocked. Simulation includes a round- robin scheduler * with time slice scheduling. Need to implement a basic Proc ess * Control Block (PCB) in order to implement the round robin scheduler. * Program will also have ready queues, and possible queues o r other * structures to keep track of blocked processes and the events they * are waiting on. * */ #include<stdlib.h> #include<iostream> #include<fstream> #include<string>
  • 41. usingnamespace std; /** The process simulator. * The main loop for running a simulation. We read simulation * events from a file * * @param simfilename The name of the file (e.g. simulaiton- 01.sim) to open * and read simulated event sequence from. * @param timeSliceQuantum The value to be used for system ti me slicing preemption * for this simulation. */ void runSimulation(char* simfilename,int timeSliceQuantum) { ifstream simeventsfile(simfilename); string command; int eventnum; if(!simeventsfile.is_open()) { cout <<"Error: could not open simulator events file: "<< simf ilename << endl; exit(1); } while(!simeventsfile.eof()) { simeventsfile >> command; // Handle the next simulated event we just read from the // simulation event file if(command =="cpu") {
  • 42. cout <<" cpu: simulate a cpu cycle here"<< endl; } elseif(command =="new") { cout <<" new: simulate creation of new process here"<< e ndl; } elseif(command =="done") { cout <<" done: simulate termination of currently running p rocess here"<< endl; } elseif(command =="wait") { simeventsfile >> eventnum; cout <<" wait: eventnum: "<< eventnum << " simulate event blocked and waiting"<< endl; } elseif(command =="event") { simeventsfile >> eventnum; cout <<" event: eventnum: "<< eventnum << " simulate event occurring possibly making some processes read y"<< endl; } elseif(command =="exit") { // we use an explicit indicator to ensure simulation exits correctl y break; } else { cout <<" ERROR: unknown command: "<< command << e ndl; exit(0);
  • 43. } } simeventsfile.close(); } /** Main entry point of simulator * The main entry point of the process simulator. We simply se t up * and initialize the environment, then call the appropriate func tion * to begin the simulation. We expect a single command line ar gument * which is the name of the simulation event file to process. * * @param argc The argument count * @param argv The command line argument values. We expect argv[1] to be the * name of a file in the current directory holding proces s events * to simulate. */ int main(int argc,char** argv) { int timeSliceQuantum =0; // validate command line arguments if(argc !=3) { cout <<"Error: expecting event file as first command line par ameter and time slice quantum as second"<< endl; cout <<"Usage: "<< argv[0]<<" simeventfile.sim time_slice" << endl; exit(1); }
  • 44. // Assume second command line argument is the time slice quan tum and parse it timeSliceQuantum = atoi(argv[2]); if(timeSliceQuantum <=0) { cout <<"Error: invalid time slice quantum received: "<< time SliceQuantum << endl; exit(1); } // Invoke the function to actually run the simulation runSimulation(argv[1], timeSliceQuantum); // if don't want to use command line do following. // need to recompile by hand since file // name to get simulated events from is hard coded //runSimulation("simulation-01.sim", 5); return0; } p2-start.c /** * @author Your Name Here * @cwid 123 45 678 * @class CSci 430, Summer 2017 * @ide Visual Studio Express 2017 * @date June 11, 2017 * @assg Programming Assignment #2 * * @description Implement a simulation of a basic 3 process state system * Ready, Running, Blocked. Simulation includes a round- robin scheduler
  • 45. * with time slice scheduling. Need to implement a basic Process * Control Block (PCB) in order to implement the round robin scheduler. * Program will also have ready queues, and possible queues or other * structures to keep track of blocked processes and the events they * are waiting on. * */ #include <stdlib.h> #include <stdio.h> #include <string.h> /** The process simulator. * The main loop for running a simulation. We read simulation * events from a file * * @param simfilename The name of the file (e.g. simulaiton- 01.sim) to open * and read simulated event sequence from. * @param timeSliceQuantum The value to be used for system time slicing preemption * for this simulation. */ void runSimulation(char* simfilename, int timeSliceQuantum) { FILE* simeventsfile; char line[256]; // temporary buffer to hold the whole line we read in char* command; char* eventnumstr; int eventnum;
  • 46. // open the simulation file, and make sure we were successful // before continuing simeventsfile = fopen(simfilename, "r"); if (!simeventsfile) { fprintf(stderr, "Error: could not open simulator events file: %sn", simfilename); exit(1); } while (fgets(line, sizeof(line), simeventsfile)) { // get first token from line, up to first whitespace character, put into command command = strtok(line, " tn"); // splits line on space, tab or newline // Handle the next simulated event we just read from the // simulation event file if (strcmp(command, "cpu") == 0) { printf(" cpu: simulate a cpu cycle heren"); } else if (strcmp(command, "new") == 0) { printf(" new: simulate creation of a new process heren"); } else if (strcmp(command, "done") == 0) { printf(" done: simulate termination of currently running process heren"); } else if (strcmp(command, "wait") == 0) { eventnumstr = strtok(NULL, " tn"); // get pointer to event number string
  • 47. sscanf(eventnumstr, "%d", &eventnum); printf(" wait: eventnum: %d simulate event blocked and waitingn", eventnum); } else if (strcmp(command, "event") == 0) { eventnumstr = strtok(NULL, " tn"); // get pointer to event number string sscanf(eventnumstr, "%d", &eventnum); printf(" event: eventnum: %d simulate event occurring possibly making some processes readyn", eventnum); } else if (strcmp(command, "exit") == 0) { // we use an explicit indicator to ensure simulation exits correctly break; } else { fprintf(stderr, "Error: unknown command: %sn", command); exit(0); } } fclose(simeventsfile); } /** Main entry point of simulator * The main entry point of the process simulator. We simply set up * and initialize the environment, then call the appropriate function * to begin the simulation. We expect a single command line
  • 48. argument * which is the name of the simulation event file to process. * * @param argc The argument count * @param argv The command line argument values. We expect argv[1] to be the * name of a file in the current directory holding process events * to simulate. */ int main(int argc, char** argv) { int timeSliceQuantum = 0; // validate command line arguments if (argc != 3) { printf("Error: expecting event file as first command line parameter and time slice quantum as secondn"); printf("Usage: %s simeventfile.sim time_slicen", argv[0]); exit(1); } // Assume second command line argument is the time slice quantum and parse it timeSliceQuantum = atoi(argv[2]); if (timeSliceQuantum <= 0) { printf("Error: invalid time slice quantum received: %dn", timeSliceQuantum); exit(1); } // Invoke the function to actually run the simulation runSimulation(argv[1], timeSliceQuantum);
  • 49. // if don't want to use command line do following. // need to recompile by hand since file // name to get simulated events from is hard coded //runSimulation("simulation-01.sim", 5); return 0; } prog-02.pdf 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.
  • 50. 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 �le. The input describes a time sequence of events that occur. These are the full set of events you will simulate: 1 Event Description cpu 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 �nished 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 �le will simply be a list of events that occur in the system, in the order they are to occur. For example: ----- simulation-01.sim --------
  • 52. 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: 2 � De�ne a simple process control block (PCB) to hold information about all processes currently running in your system. The PCB can be a simple C struct or a C++ class. At a minimum you need to have a �eld for the process identi�er 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
  • 53. 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. Whenever 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 �lling 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 identi�er. The process identi�er should be a
  • 54. 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 3 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 �nishing 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
  • 55. 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
  • 56. 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): 4 pid=1, state=RUNNING, start=1, slice=4, Ready Queue: pid=2, state=READY, start=4, slice=0, Blocked Queue: EMPTY
  • 57. 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:
  • 58. 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): 5 pid=1, state=RUNNING, start=1, slice=2, Ready Queue: EMPTY Blocked Queue:
  • 59. 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,
  • 60. 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): 6 pid=2, state=RUNNING, start=4, slice=3, Ready Queue: EMPTY
  • 61. 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 di� and your program is generating the correct output, then there will be no di�erence 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 queues. Note that the queues are displayed in order. The top of the output corresponds to the head of the
  • 62. queue. Thus when a new process is dispatched, the next one selected should be the �rst process listed from the ready queue in the previous system cycle. I have given you some template code (p2-start.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 �le 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 �gure out how to invoke running it from the command line, you can change the line in 'p2-start.cpp' to explicitly run a particular simulation �le, like this: runSimulation("simulation-01.sim", time_slice_quantum) 7 However, you need to make sure that your program correctly works using the command line invocation, as shown in `p2-start.cpp`. I have given some template code to get you started in the �le
  • 63. called p2-start.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 �le events. Your job is to implement the necessary actions and data structures to handle the simulated events described. The runSimulation() in 'p2-start.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 �les you create for you solution (.c or .cpp/.c++ and .h header �les) should be uploaded to the MyLeo Online submission folder created for this assignment by the deadline. You should not attach any �les besides the source �les containing your C/C++ code. But you should make sure you attach all needed �les 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 �ne, or the more recent C99 C++11 will also be acceptable), and/or recent IDE that has an up to date compiler. You should
  • 64. only use standard C/C++ libraries, do not use Microsoft speci�c 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 class, if you would like an example implementation in plain C that might be simpler to use than learning the STL. 8 http://en.cppreference.com/w/ simulation-01.sim new cpu cpu cpu new cpu cpu cpu cpu wait 1 cpu cpu event 1 cpu
  • 68. wait 2 cpu cpu cpu event 1 cpu cpu event 3 cpu cpu cpu cpu cpu done cpu cpu cpu cpu done event 2 cpu cpu cpu wait 1 cpu cpu cpu cpu cpu done cpu done event 1 cpu cpu done
  • 72. cpu cpu cpu cpu wait 1 cpu wait 1 cpu wait 1 cpu wait 1 cpu wait 1 cpu wait 1 cpu wait 1 cpu event 1 cpu cpu cpu cpu cpu cpu cpu cpu cpu cpu cpu cpu cpu cpu cpu cpu cpu