SlideShare a Scribd company logo
1 of 103
1) According to Cudd and Jones, the term 'sexism' refers to
which of the following?
a. The unjustified systemic disadvantage faced by women.
b. Anything that involves treating men and women differently.
c. Anything that makes women less well-off than men.
d. The widely held belief that women are inferior to men and
deserve less.
2) According to Frye, what is a double bind?
a) It is a situation where choices are reduced to a few, and all of
those choices have bad outcomes.
b) The double bind is a kind of knot used by sailors.
c) It is a situation where the choices of an oppressor bind the
oppressed.
d) It is situation where one is bound by multiple social forces
and has no choice in what to do.
3) What is the purpose of Frye's discussion of the custom of
men opening doors for women?
a) To illustrate an example of a double bind.
b) To show that some customs based on gender are okay when
helpful.
c) To show that if a man ever opens a door for a woman, he is
being sexist.
d) To illustrate the difference between macroscopic and
microscopic modes of analysis.
4) Which of the following best characterizes the role of sex in
advertising according to Bordo?
a) Sex doesn't really play a noticeable role in advertising, which
is about getting information about a product into the world.
b) Women's eating serves as a metaphor for sexual experience,
while men's sexual appetite is a metaphor for their hunger.
c) Sexual desire is natural for men so it is openly depicted, but
for women such desire must be hidden through subtle hints.
d) Sex sells, so putting attractive members of the opposite sex
near product will lead to positive attitudes toward the product.
5) Which of the following possible causes of poverty does "The
End of Poverty" emphasize?
a) Colonialism as it transformed from political to contemporary
economic forms
b) Political corruption in countries with developing economies
c) Bad education and work habits among citizens of developing
nations
d) Greed on the part of owners of major companies
6) "The Debt of Dictators" suggests that the US and other
developed nations had which of the following roles in creating
the debt of dictators?
a) Developed nations were largely uninvolved in the debt of
dictators
b) Developed nations were usually forced to loan money to
dictators for humanitarian reasons
c) Developed nations willingly lent money to corrupt dictators
because it was profitable to do so
d) Developed nations borrowed money from dictators to fund
extravagant social welfare programs
7) Which of the following best characterizes Pogge's thesis?
a) Most people in the US are actively harming those
impoverished around the world, and consequently have an
obligation to alleviate poverty
b) Most people in the US can help the impoverished around the
world at little cost; while they are not obligated to do so, they
would be more virtuous if they did so
c) Most people in the US are uninvolved in global injustice, and
are not in a position to do anything about it
d) Most people in the US are not actively harming the
impoverished, but can still help them at little cost to
themselves, therefore have an obligation to help them
8) What is an intermediate duty according to Pogge?
a) An Intermediate duty occupies the mean between excess and
deficiency in the character of the agent who acts
b) Between positive and negative duties, intermediate duty
requires action by agents, but is grounded in their duty not to
harm others
c) An intermediate duty is one that balances the costs against
the expected benefits of an action
d) Between perfect and imperfect duties, intermediate duties are
always obligatory, but only under certain circumstances
JGilchrist_lab1 Code.txt
/*
* File: week1ECET360.cpp
* Author: JGilchrist
*
* Created on November 5, 2013, 8:20 PM
*/
#pragma GCC diagnostic ignored "-Wwrite-strings" //compiler
directive? Cplusplus.com
#include <cstdlib> // for EXIT_SUCCESS and EXIT_FAILURE
#include <iostream> // for cout, endl, and cin
#include <stdio.h>
#include <sys/wait.h> // for wait()
#include <unistd.h> // for pipe(), read(), write(), close(), fork(),
and _exit()
using namespace std;
/***************************************
*Used from the the partial code given
****************************************/
/* Commander Process: */
int main(int argc, char** argv) {
int result = 0;
int pfd[2];
pid_t cpid; //cpid of type integer defined types.h //Via Paul
Nichols
bool parentLoop = true;//control variable for write loop,
break?CPlusplus.con
char userInput; //user input
if (pipe(pfd) == -1) {//creating the pipe
perror("pipe failed");
exit(EXIT_FAILURE);
}
//fork a child process after the pipe is made so they both have
same PFD via http://www.advancedlinuxprogramming.com/alp-
folder/alp-ch03-processes.pdf
cpid = fork();
if (cpid == -1) {//if fork returned error exit
perror("fork failed"); //via Paul Nichols
exit(EXIT_FAILURE);
}
//wait for a second so child doesnt write over parent
sleep(1);//linux sleep 1 second if using windows
Sleep(milliseconds)
if(cpid != 0) { //this is the parent-->Commander
process**********************************************
***
close(pfd[0]); //closing read end on parent...parent only
writes
cout << "commands are 'Q', 'U', 'P', or 'T' to quit"<<endl;
while(parentLoop == true){
sleep(1);//linux sleep 1 second if using windows
Sleep(milliseconds)
cout << "enter a command: ";
cin >> userInput;
cout << endl; // cout for the user input
if((userInput=='Q') ||
(userInput=='U')||(userInput=='P')){
/************************************************
************************************
* The commander process accepts four commands:
Used from the ILab Tab
* 1. Q: End of one unit of time.
* 2. U: Unblock the first simulated process in
blocked queue.
* 3. P: Print the current state of the system.
* 4. T: Print the average turn around time,
and terminate the system.
************************************************
*************************************/
//write info to pipe
if(write(pfd[1], &userInput, sizeof(userInput)) <
0)
exit(EXIT_FAILURE);
//sleep(.5);//linux sleep 1 second if using
windows Sleep(milliseconds)
}
else if(userInput == 'T'){
cout << "user input is T...Terminating parent" <<
endl;
parentLoop = false;
if(write(pfd[1], &userInput, 1) < 0){
perror("pipe write failed");
exit(EXIT_FAILURE);
}
}
else {
cout << "invalid input, please enter values of 'Q', 'U',
'P', or 'T' to quitn" << endl;
}
}
cout << "waiting for child process to close.."<<endl;
close(pfd[1]);//close write end of pipe
wait(NULL);// wait for child to close
exit(EXIT_SUCCESS);
}//end of parent process
code*************************************************
***************************
else { //this is child--swap--> Process Manager process
//execl( project_manager_loc , "Project_Manager",
argv[1], &string1[0], (char *) 0);
close(pfd[1]);//close write end of pipe
char *project_manager_loc = "./Project_Manager";
char string1[12]; // A 32 bit number can't take more than
11 characters, + a terminating 0
snprintf(string1,12,"%i",pfd[0]); // Copy the file descriptor
into a string
char *args_1[] = {"Project_Manager", argv[0],
&string1[0], (char *) 0};
execve( project_manager_loc , args_1, NULL);
cout << "Error executing child...can not open" <<
endl;
close(pfd[0]);
cout << "exiting" << endl;
}//end process
_exit(result);
}
Archive created by free jZip.url
[InternetShortcut]
URL=http://www.jzip.com/archive_link
JGilchrist_Ilab2_execution_file.txt
/*
* File: week1ECET360Execution.cpp
* Author: JGilchrist
* Tutor: Paul Nichols
* References used:
http://www.advancedlinuxprogramming.com/alp-folder/alp-
ch03-processes.pdf
* cplusplus.com, stackedoverflow.com
* Created on November 10, 2013, 6:20 PM
*/
#include <cctype> // for toupper()
#include <cstdlib> // for EXIT_SUCCESS and EXIT_FAILURE
#include <cstring> // for strerror()
#include <cerrno> // for errno
#include <deque> // for deque (used for ready and blocked
queues)
#include <fstream> // for ifstream (used for reading simulated
process programs)
#include <iostream> // for cout, endl, and cin
#include <sstream> // for stringstream (for parsing simulated
process programs)
#include <sys/wait.h> // for wait()
#include <unistd.h> // for pipe(), read(), write(), close(), fork(),
and _exit()
#include <vector> // for vector (used for PCB table)
#include <stdexcept> // std::out_of_range
using namespace std;
class Instruction {//file instruction format
public:
char operation;
int intArg;
string stringArg;
};
/****************************************************
*****************************************************
* Cpu is used to simulate the execution of a simulated process
that is in running state.
* It should include data members to store a pointer to the
program array, current program counter value,
* integer value, and time slice of that simulated process. In
addition, it should store the number of
* time units used so far in the current time slice.
*****************************************************
****************************************************/
class Cpu {
public:
vector<Instruction> *pProgram;//this is a pointer to
PcbEntry.program
int programCounter;
int value;
int timeSlice;//curent time slice
int timeSliceUsed;//time units used so far in current time
slice
};
enum State {//curent state of pcbEntry
STATE_READY,
STATE_RUNNING,
STATE_BLOCKED
};
class PcbEntry {//class of values to save in PCB table
public:
int processId;
int parentProcessId;
vector<Instruction> program;//program is a list Instruction
class objects(char operation, int, string)
unsigned int programCounter;
int value;
unsigned int priority;
State state;
unsigned int startTime; // For iLab 3, unused for iLab 2
unsigned int timeUsed; // For iLab 3, unused for iLab 2
};
unsigned int timestamp = 0; // The current simulation time.
Cpu cpu; // The current CPU state.
// For the states below, -1 indicates empty (since it is an invalid
index).***see State description
/****************************************************
*************************************************
* RunningState stores the PcbTable index of the currently
running simulated process.
*****************************************************
**************************************************/
int runningState = -1; // The index of the running process in the
PCB table.
/****************************************************
************************************************
* ReadyState stores all simulated processes (PcbTable indices)
that are ready to run.
* This can be implemented using a queue or priority queue data
structure.
*****************************************************
***********************************************/
deque<int> readyState; // A queue of PCB indices for ready
processes.(index)
/****************************************************
*************************************************
* BlockedState stores all processes (PcbTable indices) that are
currently blocked.
* This can be implemented using a queue data structure.
*****************************************************
**************************************************/
deque<int> blockedState; // A queue of PCB indices for blocked
processes.
// In this implementation, we'll never explicitly clear PCB
entries and the
// index in the table will always be the process ID. These
choices waste memory,
// but since this program is just a simulation it the easiest
approach.
// Additionally, debugging is simpler since table slots and
process IDs are
// never re-used.
/****************************************************
*****************************************************
* PcbTable is an array with one entry for every simulated
process that hasn't finished its execution yet.
* Each entry should include data members to store process id,
parent process id, a pointer to program counter
* value (initially 0), integer value, priority, state, start time,
and CPU time used so far.
*****************************************************
***************************************************/
vector<PcbEntry *> pcbTable;
double cumulativeTimeDiff = 0;
int numTerminatedProcesses = 0;
// Sadly, C++ has no built-in way to trim strings:
string& trim(string &argument)
{
string whitespace(" tnvfr");
size_t found = argument.find_last_not_of(whitespace);
if (found != string::npos) {
argument.erase(found + 1);
argument.erase(0,
argument.find_first_not_of(whitespace));
} else {
argument.clear(); // all whitespace
}
return argument;
}
bool createProgram(const string &filename, vector<Instruction>
&program)
{
cout << "running creatProgram process " << endl;
ifstream file; //open a stream to "init" named file
int lineNum = 0;
file.open(filename.c_str());
if (!file.is_open()) {
cout << " file open: Error opening file " << filename <<
endl;
return false;
}
while (file.good()) {//------------------- process init file -------
-------------------------------------
string line;
getline(file, line);
cout << " read from " << filename.c_str() << " : " << line
<< endl;
trim(line);
if (line.size() > 0) {
Instruction instruction;
instruction.operation = toupper(line[0]);
instruction.stringArg = trim(line.erase(0, 1));
stringstream argStream(instruction.stringArg);
switch (instruction.operation) {
case 'S': // Integer argument.
case 'A': // Integer argument.
case 'D': // Integer argument.
case 'F': // Integer argument.
if (!(argStream >> instruction.intArg)) {
cout << filename << ":" << lineNum
<< " - Invalid integer argument "
<< instruction.stringArg << " for "
<< instruction.operation << " operation" <<
endl;
file.close();
return false;
}
break;
case 'B': // No argument.
case 'E': // No argument.
break;
case 'R': // String argument.
// Note that since the string is trimmed on both
ends,
// filenames with leading or trailing whitespace
(unlikely)
// will not work.
if (instruction.stringArg.size() == 0) {
cout << filename << ":" << lineNum
<< " - Missing string argument" << endl;
file.close();
return false;
}
break;
default:
cout << filename << ":" << lineNum
<< " - Invalid operation, " <<
instruction.operation
<< endl;
file.close();
return false;
}
program.push_back(instruction);
}
lineNum++;
}//-------------------------------- finished processing the file ---
----------------------/
file.close();
return true;
}
/****************************************************
*****************************************
* Instructions S, A and D update the integer value stored in
Cpu.
*****************************************************
***************************************/
void set(int value){
cpu.value = value;
cout << "running set process...setting cpu value to "<<
cpu.value << endl;
}
void add(int value){
cpu.value = cpu.value + value;
cout << "running +add process new cpu value = "<<
cpu.value << endl;
}
void decrement(int value){
cpu.value = cpu.value - value;
cout << "running -decrement process new cpu value = " <<
cpu.value << endl;
}
// Performs scheduling.
void schedule()
{
cout << "running schedule process ";
cout << " PID = " << runningState << " ";
// 1. Return if there is still a processing running
(runningState != -1).
if (runningState == -1 && !readyState.empty()){//nothing
running and process is in queue
// 2. Get a new process to run, if possible, from the
readystate queue.
runningState = readyState.front();//retrieve the index
of the pcbTable that is ready to run
cout << "...loading new process from que pid is " <<
runningState << endl;
readyState.pop_front();//remove it from queue push
back-->pop front;
// 3. If we were able to get a new process to run:
// a. Mark the processing as running (update new
process's PCB state)
//***warning*** if pcbTable[location] does not exist
you are exited!!!!
pcbTable[runningState]->state = STATE_RUNNING;
//cout << "SET NEW RUNNING STATE" << endl;
// b. Update the CPU structure with the PCB entry details
(program,
// program counter, value, etc.)
cpu.pProgram = &pcbTable[runningState]-
>program;//the whole list
//cout << "SET NEW PROGRAM" << endl;
cpu.programCounter = pcbTable[runningState]-
>programCounter;
//cout << "SET NEW PROGRAM COUNTER" <<
endl;
cpu.value = pcbTable[runningState]->value;
//cout << "SET NEW VALUE" << endl;
cpu.timeSlice = pcbTable[runningState]->startTime;
//cout << "SET NEW TIMESLICE" << endl;
cpu.timeSliceUsed = pcbTable[runningState]-
>timeUsed;
}
else if ((runningState == -1)&& (readyState.empty())) cout
<< "nothing in queue and nothing running blocked state = " <<
blockedState.size()<< " try and Unblock "<< endl;
else cout << "...process is running" << endl;
}
/****************************************************
**************************************
* Instruction B moves the currently running simulated process
to the blocked state
* and moves a process from the ready state to the running
state.
* This will result in a context switch.
*****************************************************
************************************/
void block()
{
cout << "running block process " << endl;
// 1. Add the PCB index of the running process (stored in
runningState) to
// the blocked queue.
blockedState.push_back(runningState);//push back pull
front
// 2. Update the process's PCB entry
// a. Change the PCB's state to blocked.
// b. Store the CPU program counter in the PCB's program
counter.
// c. Store the CPU's value in the PCB's value
cout << " adding pid = " << pcbTable[runningState]-
>processId << " to the block queue" <<endl;
pcbTable[runningState]->state = STATE_BLOCKED;
pcbTable[runningState]->programCounter =
cpu.programCounter;
pcbTable[runningState]->value = cpu.value;
// 3. Update the running state to -1 (basically mark no
process as running).
// Note that a new process will be chosen to run later (via
the Q command
// code calling the schedule() function).
runningState = -1;
}
/****************************************************
**************************************
* Instruction E terminates the currently running simulated
process, frees up all memory
* (e.g. program array) associated with that process and updates
the PcbTable.
* A simulated process from the ready state is moved to
running state.
* This also results in a context switch.
*****************************************************
**************************************/
void end()
{
cout << "running end process " << endl;
// TODO:Get the PCB entry of the running process.
cumulativeTimeDiff = timestamp + 1 -
pcbTable[runningState]->startTime;
++numTerminatedProcesses;
runningState = -1;
// memory will get freed when the simulation terminates.
}
/****************************************************
***************************************************
* Instruction F results in the creation of a new simulated
process. A new entry is created in
* the PcbTable for this new simulated process. A new (unique)
process id is assigned and the
* parent process id is process id of the parent simulated
process. Start time is set to the current
* Time value and CPU time used so far is set to 0. The
program array and integer value of the new
* simulated process are a copy of the program array and
integer value of the parent simulated process.
* The new simulated process has the same priority as the
parent simulated process.
*
* The program counter value of the new simulated process is
set to the instruction immediately
* after the F instruction, while the program counter value of
the of the parent simulated process
* is set to n instructions after the next instruction (instruction
immediately after F).
*
* The new simulated process is created in the ready state.
*****************************************************
**************************************************/
void fork(int value)
{
cout << "running fork process " << endl;
PcbEntry *myPCB = new PcbEntry();
myPCB->program = pcbTable[runningState]->program;
if ((value > -2) && (value < 1000)){//ensure passed in
method not out of bounds
try{//catch all out of range
myPCB->processId = pcbTable.size();//a PCB
index+table.size
myPCB->parentProcessId =
pcbTable[runningState]->processId;
myPCB->programCounter =
cpu.programCounter;
myPCB->value = cpu.value;
myPCB->priority = pcbTable[runningState]-
>priority;
myPCB->state = STATE_READY;//dont forget
to add to ready queue
myPCB->startTime = timestamp;
pcbTable.push_back(myPCB);//queue push back,
pull front
readyState.push_back(myPCB->processId);
cpu.programCounter = cpu.programCounter +
value;
cout << " forked process, pid = " << myPCB-
>processId << " and pushed it to the ready queue" << endl;
}
catch (const out_of_range& oor) {
std::cerr << "Out of Range error: " <<
oor.what() << 'n';
}
catch(const runtime_error& re)
{
cout << "Exception caught: " << re.what() <<
'n';
}
}
else cout << "value is out of bounds" << endl;
}
/****************************************************
**************************************************
* The R instruction results in replacing the process image of
the currently
* running simulated process. Its program array is overwritten
by the code in file filename,
* program counter value is set to 0, and integer value is
undefined. Note that all these changes
* are made only in the Cpu data structure. Process id, parent
process id, start time,
* CPU time used so far, state, and priority remain unchanged.
*****************************************************
************************************************/
void replace(string &argument)
{
cout << "running replace process opening file " << endl;
cpu.pProgram->clear();//shouldnt I read argument first?
cout << "replace argument is " << argument << endl;
if (!createProgram(argument, *cpu.pProgram)) {//storing file
into pProgram
cout << " ERROR can not open file!" << endl;
cpu.programCounter = cpu.programCounter + 1;
//do more error handling
}
else {
cpu.programCounter = 0;
cout << " createprogram..sucess" << endl;
}
}
// Implements the Q command.
/****************************************************
*************************************************
* On receiving a Q command,
* the process manager executes the next instruction of the
currently running simulated process,
* increments program counter value (except for F or R
instructions), increments Time,
* and then performs scheduling. Note that scheduling may
involve performing context switching.
*****************************************************
************************************************/
void quantum()
{
cout << "starting quantum process " << endl;
Instruction instruction;
if (runningState == -1) {
cout << "No processes are running" << endl;
++timestamp;
return;
}
if (cpu.programCounter < cpu.pProgram->size()) {
instruction = (*cpu.pProgram)[cpu.programCounter];
cpu.programCounter++;
} else {
cout << "End of program reached without E operation" <<
endl;
instruction.operation = 'E';
}
switch (instruction.operation) {
case 'S':
set(instruction.intArg);
break;
case 'A':
add(instruction.intArg);
break;
case 'D':
decrement(instruction.intArg);
break;
case 'B':
block();
break;
case 'E':
end();
break;
case 'F':
fork(instruction.intArg);
break;
case 'R':
replace(instruction.stringArg);
break;
}
++timestamp;
schedule();
}
// Implements the U command.
void unblock()
{
cout << "entered unblocked method" << endl;
if(!blockedState.empty()){//check for empty queue
int pcbIndex = blockedState.front();
cout << " unblocking PID = " << pcbIndex << " adding it
to ready que" << endl;
blockedState.pop_front();
readyState.push_back(pcbIndex);
pcbTable[pcbIndex]->state = STATE_READY;
schedule();
}
else {cout << " blocked buffer was empty" << endl; }
}
/****************************************************
*********************************************
* On receiving a P command, the process manager spawns a
new reporter process.
*****************************************************
*******************************************/
void print()
{
cout << "Print command is not implemented until iLab 3" <<
endl;
}
// Function that implements the process manager.
/****************************************************
*********************************************
* The process manager process simulates four process
management functions:
* 1. creation of new (simulated) processes,
* 2. replacing the current process image of a simulated process
with a new process image,
* 3. management of process state transitions,
* 4. process scheduling.
*****************************************************
********************************************/
int runProcessManager(int fileDescriptor)
{
PcbEntry *pcbEntry = new PcbEntry();
const char *INITPATH = "init";
// Attempt to create the init process.
/****************************************************
***************************************************
* The process manager creates[createProgram()] the first
simulated process (process id = 0) program from an input file
* (filename: init). This is the only simulated process created
by the process manager on its own.
* All other simulated processes are created in response to
the execution of the F instruction
*
*****************************************************
************************************************/
if (!createProgram(INITPATH , pcbEntry->program)) {
delete pcbEntry;
return EXIT_FAILURE;
}
/****************************************************
****************************************************
* The process manager maintains six data structures: They
are in the pcbEntry class
* Time, Cpu, PcbTable, {[state::] ReadyState, BlockedState,
and RunningState.}
*****************************************************
*************************************************/
pcbEntry->processId = pcbTable.size();
pcbEntry->parentProcessId = -1;
pcbEntry->programCounter = 0;
pcbEntry->value = 0;
pcbEntry->priority = 0;
pcbEntry->state = STATE_RUNNING;
// Time is an integer variable initialized to zero.
pcbEntry->startTime = 0;
pcbEntry->timeUsed = 0;
/****************************************************
*****************************************************
* PcbTable is an array with one entry for every simulated
process that hasn't finished its execution yet.
* Each entry should include data members to store process
id, parent process id, a pointer to program counter
* value (initially 0), integer value, priority, state, start time,
and CPU time used so far.
*****************************************************
***************************************************/
pcbTable.push_back(pcbEntry);
runningState = pcbEntry->processId;
cout << "Running init process, pid = " << pcbEntry-
>processId << endl;
/****************************************************
*****************************************************
* Cpu is used to simulate the execution of a simulated
process that is in running state.
* It should include data members to store a pointer to the
program array, current program counter value,
* integer value, and time slice of that simulated process. In
addition, it should store the number of
* time units used so far in the current time slice.
*****************************************************
****************************************************/
cpu.pProgram = &(pcbEntry->program);
cpu.programCounter = pcbEntry->programCounter;
cpu.value = pcbEntry->value;
timestamp = 0;
double avgTurnaroundTime = 0;
// Loop until a 'T' is read, then terminate.
char ch;
do {
// Read a command character from the pipe.
/************************************************
****************************************************
* After creating the first process and initializing all its
data structures,
* the process manager repeatedly receives and processes
one command at a time
* from the commander process (read via the pipe).
*
*****************************************************
*********************************************/
if (read(fileDescriptor, &ch, sizeof(ch)) != sizeof(ch)) {
// Assume the parent process exited, breaking the pipe.
break;
}
// Ignore whitespace characters.
if (isspace(ch)) {
continue;
}
// Convert commands to a common case so both lower and
uppercase
// commands can be used.
ch = toupper(ch);
switch (ch) {
case 'Q':
quantum();
break;
case 'U':
unblock();
break;
case 'P':
print();
break;
/****************************************************
**************************************
* On receiving a T command, the process manager first
spawns a reporter process and then
* terminates after termination of the reporter process.
The process manager ensures that
* no more than one reporter process is running at any
moment.
*****************************************************
************************************/
case 'T':
if (numTerminatedProcesses != 0) {
avgTurnaroundTime = cumulativeTimeDiff
/ (double)numTerminatedProcesses;
}
cout << "The average turnaround time is " <<
avgTurnaroundTime
<< "." << endl;
break;
default:
cout << "Unknown command, " << ch << endl;
}
} while (ch != 'T');
// Cleanup any remaining PCB entries.
for (vector<PcbEntry *>::iterator it = pcbTable.begin();
it != pcbTable.end(); it++) {
delete *it;
}
pcbTable.clear();
return EXIT_SUCCESS;
}
//recieves a pipe descriptor
int main(int argc, char** argv) {
//variables}
int result;
int pfd[2];
//read arguments
if(argc < 3) {
cout << "You must provide a pipe adress descriptor "
<< endl;
// Keeep command window open until user presses ENTER
key
cout << "Press ENTER key to exit" << endl;
cin.ignore( );
exit(0);
}
pfd[0] = atoi(argv[2]);
// Run the process manager.
result = runProcessManager(pfd[0]);
// Close the read end of the pipe for the process manager
process (for
// cleanup purposes).
cout << "closing pipe...GOODBYE" << endl;
close(pfd[0]);//close read end of pipe
//exit (using the _exit() system call).
exit(result);
// Keeep command window open until user presses ENTER
key
cout << "Press ENTER key to exit" << endl;
cin.ignore( );
return(0);
}
JGilchrist_lab2 Code.txt
/*
* File: week1ECET360.cpp
* Author: JGilchrist
*
* Created on November 5, 2013, 8:20 PM
*/
#pragma GCC diagnostic ignored "-Wwrite-strings" //compiler
directive? Cplusplus.com
#include <cstdlib> // for EXIT_SUCCESS and EXIT_FAILURE
#include <iostream> // for cout, endl, and cin
#include <stdio.h>
#include <sys/wait.h> // for wait()
#include <unistd.h> // for pipe(), read(), write(), close(), fork(),
and _exit()
using namespace std;
/***************************************
*Used from the the partial code given
****************************************/
/* Commander Process: */
int main(int argc, char** argv) {
int result = 0;
int pfd[2];
pid_t cpid; //cpid of type integer defined types.h //Via Paul
Nichols
bool parentLoop = true;//control variable for write loop,
break?CPlusplus.con
char userInput; //user input
if (pipe(pfd) == -1) {//creating the pipe
perror("pipe failed");
exit(EXIT_FAILURE);
}
//fork a child process after the pipe is made so they both have
same PFD via http://www.advancedlinuxprogramming.com/alp-
folder/alp-ch03-processes.pdf
cpid = fork();
if (cpid == -1) {//if fork returned error exit
perror("fork failed"); //via Paul Nichols
exit(EXIT_FAILURE);
}
//wait for a second so child doesnt write over parent
sleep(1);//linux sleep 1 second if using windows
Sleep(milliseconds)
if(cpid != 0) { //this is the parent-->Commander
process**********************************************
***
close(pfd[0]); //closing read end on parent...parent only
writes
cout << "commands are 'Q', 'U', 'P', or 'T' to quit"<<endl;
while(parentLoop == true){
sleep(1);//linux sleep 1 second if using windows
Sleep(milliseconds)
cout << "enter a command: ";
cin >> userInput;
cout << endl; // cout for the user input
if((userInput=='Q') ||
(userInput=='U')||(userInput=='P')){
/************************************************
************************************
* The commander process accepts four commands:
Used from the ILab Tab
* 1. Q: End of one unit of time.
* 2. U: Unblock the first simulated process in
blocked queue.
* 3. P: Print the current state of the system.
* 4. T: Print the average turn around time,
and terminate the system.
************************************************
*************************************/
//write info to pipe
if(write(pfd[1], &userInput, sizeof(userInput)) <
0)
exit(EXIT_FAILURE);
//sleep(.5);//linux sleep 1 second if using
windows Sleep(milliseconds)
}
else if(userInput == 'T'){
cout << "user input is T...Terminating parent" <<
endl;
parentLoop = false;
if(write(pfd[1], &userInput, 1) < 0){
perror("pipe write failed");
exit(EXIT_FAILURE);
}
}
else {
cout << "invalid input, please enter values of 'Q', 'U',
'P', or 'T' to quitn" << endl;
}
}
cout << "waiting for child process to close.."<<endl;
close(pfd[1]);//close write end of pipe
wait(NULL);// wait for child to close
exit(EXIT_SUCCESS);
}//end of parent process
code*************************************************
***************************
else { //this is child--swap--> Process Manager process
//execl( project_manager_loc , "Project_Manager",
argv[1], &string1[0], (char *) 0);
close(pfd[1]);//close write end of pipe
char *project_manager_loc = "./Project_Manager";
char string1[12]; // A 32 bit number can't take more than
11 characters, + a terminating 0
snprintf(string1,12,"%i",pfd[0]); // Copy the file descriptor
into a string
char *args_1[] = {"Project_Manager", argv[0],
&string1[0], (char *) 0};
execve( project_manager_loc , args_1, NULL);
cout << "Error executing child...can not open" <<
endl;
close(pfd[0]);
cout << "exiting" << endl;
}//end process
_exit(result);
}
week2.png
JGilchrist_Lab3_7.txt
#define ENABLE_COMMANDER
#define ENABLE_REPORTER
#include <cctype> // for toupper()
#include <cstdlib> // for EXIT_SUCCESS and EXIT_FAILURE
#include <cstring> // for strerror()
#include <cerrno> // for errno
#include <deque> // for deque (used for ready and blocked
queues)
#include <fstream> // for ifstream (used for reading simulated
process programs)
#include <iostream> // for cout, endl, and cin
#include <sstream> // for stringstream (for parsing simulated
process programs)
#include <sys/wait.h> // for wait()
#include <unistd.h> // for pipe(), read(), write(), close(), fork(),
and _exit()
#include <vector> // for vector (used for PCB table)
using namespace std;
class Instruction {
public:
char operation;
int intArg;
string stringArg;
};
class Cpu {
public:
vector<Instruction> *pProgram;
int programCounter;
int value;
int timeSlice;
int timeSliceUsed;
};
enum State {
STATE_READY,
STATE_RUNNING,
STATE_BLOCKED,
STATE_END
};
class PcbEntry {
public:
int processId;
int parentProcessId;
vector<Instruction> program;
unsigned int programCounter;
int value;
unsigned int priority;
State state;
unsigned int startTime;
unsigned int timeUsed;
};
// The number of valid priorities.
#define NUM_PRIORITIES 4
// An array that maps priorities to their allotted time slices.
static const unsigned int
PRIORITY_TIME_SLICES[NUM_PRIORITIES] = {
1,
2,
4,
8
};
unsigned int timestamp = 0;
Cpu cpu;
// For the states below, -1 indicates empty (since it is an invalid
index).
int runningState = -1; // The index of the running process in the
PCB table.
// readyStates is an array of queues. Each queue holds PCB
indices for ready processes
// of a particular priority.
deque<int> readyStates[NUM_PRIORITIES];
deque<int> blockedState; // A queue fo PCB indices for blocked
processes.
deque<int> deadState;
// In this implementation, we'll never explicitly clear PCB
entries and the
// index in the table will always be the process ID. These
choices waste memory,
// but since this program is just a simulation it the easiest
approach.
// Additionally, debugging is simpler since table slots and
process IDs are
// never re-used.
vector<PcbEntry *> pcbTable;
double cumulativeTimeDiff = 0;
int numTerminatedProcesses = 0;
// Sadly, C++ has no built-in way to trim strings:
string &trim(string &argument)
{
string whitespace(" tnvfr");
size_t found = argument.find_last_not_of(whitespace);
if (found != string::npos) {
argument.erase(found + 1);
argument.erase(0,
argument.find_first_not_of(whitespace));
} else {
argument.clear(); // all whitespace
}
return argument;
}
bool createProgram(const string &filename, vector<Instruction>
&program)
{
ifstream file;
int lineNum = 0;
program.clear();
file.open(filename.c_str());
if (!file.is_open()) {
cout << "Error opening file " << filename << endl;
return false;
}
while (file.good()) {
string line;
getline(file, line);
trim(line);
if (line.size() > 0) {
Instruction instruction;
instruction.operation = toupper(line[0]);
instruction.stringArg = trim(line.erase(0, 1));
stringstream argStream(instruction.stringArg);
switch (instruction.operation) {
case 'S': // Integer argument.
case 'A': // Integer argument.
case 'D': // Integer argument.
case 'F': // Integer argument.
if (!(argStream >> instruction.intArg)) {
cout << filename << ":" << lineNum
<< " - Invalid integer argument "
<< instruction.stringArg << " for "
<< instruction.operation << " operation" <<
endl;
file.close();
return false;
}
break;
case 'B': // No argument.
case 'E': // No argument.
break;
case 'R': // String argument.
// Note that since the string is trimmed on both
ends,
// filenames with leading or trailing whitespace
(unlikely)
// will not work.
if (instruction.stringArg.size() == 0) {
cout << filename << ":" << lineNum
<< " - Missing string argument" << endl;
file.close();
return false;
}
break;
default:
cout << filename << ":" << lineNum
<< " - Invalid operation, " <<
instruction.operation
<< endl;
file.close();
return false;
}
program.push_back(instruction);
}
lineNum++;
}
file.close();
return true;
}
// Implements the S operation.
void set(int value)
{
cpu.value = value;
cout << "Set CPU value to " << value << endl;
}
// Implements the A operation.
void add(int value)
{
cpu.value += value;
cout << "Incremented CPU value by " << value << endl;
}
// Implements the D operation.
void decrement(int value)
{
cpu.value -= value;
cout << "Decremented CPU value by " << value << endl;
}
// Performs scheduling.
void schedule()
{
// TODO: Debug and test
//If runningState != -1 AND the cpu.timeSliceUsed equals or
exceeds
// cpu.timeSlice:
cout <<" cpu timeslice Used " <<
cpu.timeSliceUsed<<endl;
cout <<" cpu timeslice " << cpu.timeSlice<<endl;
if ((runningState != -1) && (cpu.timeSliceUsed >=
cpu.timeSlice)){
// 1. Get the PCB entry for runningState.
PcbEntry *myPCB = pcbTable[runningState];
// 2. Lower the process priority (remember since the
highest priority is zero,
// you actually have to increment the priority to lower
it). Also make sure to
// not increment the priority past its maximum value.
if (myPCB->priority >= 0 && myPCB->priority <
(NUM_PRIORITIES - 1)) myPCB->priority++;
// 3. Push runningState on to the end of the correct
readyStates queue (hint: use
// pcbEntry.priority to select the correct queue.
switch (myPCB->priority)
{
case 0 :
readyStates[0].push_back(runningState);
break;
case 1 :
readyStates[1].push_back(runningState);
break;
case 2 :
readyStates[2].push_back(runningState);
break;
case 3 :
readyStates[3].push_back(runningState);
break;
default:
cout << "Invalid running state" << endl;
break;
}
// 4. Update the pcbEntry:
// a. Set state to STATE_READY.
// b. Set the programCounter to cpu.programCounter.
// c. Set the value to cpu.value.
// d. Increment timeUsed by cpu.timeSliceUsed.
myPCB->state = STATE_READY;
myPCB->programCounter = cpu.programCounter;
myPCB->value = cpu.value;
myPCB->timeUsed = myPCB->timeUsed +
cpu.timeSliceUsed;
cout << " time this process has used = " << myPCB-
>timeUsed << endl;
cout << " scheduler is ending process and
decreasing priority to "<< myPCB->priority <<"n" << endl;
// 5. Set runningState to -1.
runningState = -1;
}
if (runningState != -1) {//the correct priority program is
running
cout << " correct process is running exiting scheduler"
<< endl;
return;
}
cout << " loading new process from ";
// TODO: Debug and test
// Get a new process to run, if possible, from the ready queue
in
// priority order. Remember that the highest priority is zero!
The code below
// needs to be updated/replaced since right now it only uses
the highest priority
// queue.
if(!readyStates[0].empty()){
runningState = readyStates[0].front();
cout << "priority 0 " << endl;
readyStates[0].pop_front();
}
else if(!readyStates[1].empty()){
runningState = readyStates[1].front();
cout << "priority 1" << endl;
readyStates[1].pop_front();
}
else if(!readyStates[2].empty()){
runningState = readyStates[2].front();
cout << "priority 2 " << endl;
readyStates[2].pop_front();
}
else if(!readyStates[3].empty()){
runningState = readyStates[3].front();
cout << "priority 3 " << endl;
readyStates[3].pop_front();
}
else cout << "ERROR ready state has invalid state entries";
// Make sure there is a process to run.
if (runningState != -1) {
// Mark the process as running.
PcbEntry *pcbEntry = pcbTable[runningState];
pcbEntry->state = STATE_RUNNING;
// Update the CPU with new PCB entry details.
cpu.pProgram = &pcbEntry->program;
cpu.programCounter = pcbEntry->programCounter;
cpu.value = pcbEntry->value;
// TODO: Debug and test
// Set cpu.timeSlice to the correct value (hint: use the
// global PRIORITY_TIME_SLICES array and pcbEntry-
>priority)
switch (pcbEntry->priority)
{
case 0 :
cpu.timeSlice =
PRIORITY_TIME_SLICES[0];
cout << " setting cpu.timeslice to
1"<<endl;
break;
case 1 :
cpu.timeSlice =
PRIORITY_TIME_SLICES[1];
cout << " setting cpu.timeslice to
2"<<endl;
break;
case 2 :
cpu.timeSlice =
PRIORITY_TIME_SLICES[2];
cout << " setting cpu.timeslice to
4"<<endl;
break;
case 3 :
cpu.timeSlice =
PRIORITY_TIME_SLICES[3];
cout << " setting cpu.timeslice to
8"<<endl;
break;
default:
cout << "ERROR setting cpu timeslice
Invalid priority" << endl;
break;
}
// TODO: Debug and test
// Set cpu->timeSliceUsed to zero.
cpu.timeSliceUsed = 0;
cout << "Process running, pid = " << pcbEntry->processId
<< endl;
}
}
// Implements the B operation.
void block()
{
PcbEntry *pcbEntry = pcbTable[runningState];
//TODO there is a problem with pcb time used counter will
this fix it
pcbEntry->timeUsed += cpu.timeSliceUsed + 1;//add 1 for
CPU time to block the process
// TODO: Debug and test
// Raise the process priority (remember since the highest
priority is zero,
// you actually have to decrement the priority to raise it).
Also make sure to
// not decrement the priority below zero.
if (pcbEntry->priority > 0) pcbEntry->priority--;
blockedState.push_back(runningState);
pcbEntry->state = STATE_BLOCKED;
pcbEntry->programCounter = cpu.programCounter;
pcbEntry->value = cpu.value;
runningState = -1;
cout << "Blocked process, pid = " << pcbEntry->processId
<< endl;
}
// Implements the E operation.
void end()
{
PcbEntry *pcbEntry = pcbTable[runningState];
//TODO there is a problem with pcb timused will this fix it?
pcbEntry->timeUsed = pcbEntry->timeUsed +
cpu.timeSliceUsed + 1;//add 1 to account for e operation
// Add 1 to account for the time to execute the E operation.
cumulativeTimeDiff += (double)(timestamp + 1 - pcbEntry-
>startTime);
numTerminatedProcesses++;
cout << "Ended process, pid = " << pcbEntry->processId <<
endl;
pcbEntry->state = STATE_END;
deadState.push_back(runningState);
runningState = -1;
}
// Implements the F operation.
void fork(int value)
{
int pcbIndex = (int)pcbTable.size();
PcbEntry *runningPcbEntry = pcbTable[runningState];
PcbEntry *pcbEntry = new PcbEntry();
pcbEntry->processId = pcbIndex;
pcbEntry->parentProcessId = runningPcbEntry->processId;
pcbEntry->program = runningPcbEntry->program;
pcbEntry->programCounter = cpu.programCounter;
pcbEntry->value = cpu.value;
pcbEntry->priority = runningPcbEntry->priority;
pcbEntry->state = STATE_READY;
pcbEntry->startTime = timestamp + 1;
pcbEntry->timeUsed = 0;
pcbTable.push_back(pcbEntry);
// TODO: debug and test
//Update the line below to use the correct readyStates queue.
readyStates[pcbEntry->priority].push_back(pcbIndex);
cout << "Forked new process, pid = " << pcbEntry-
>processId << endl;
if ((value < 0) ||
(cpu.programCounter + value >= (int)cpu.pProgram-
>size())) {
cout << "Error executing F operation, ending parent
process" << endl;
end();
}
cpu.programCounter += value;
}
// Implements the R operation.
void replace(string &argument)
{
if (!createProgram(argument, *cpu.pProgram)) {
cout << "Error executing R operation, ending process" <<
endl;
end();
return;
}
cpu.programCounter = 0;
cout << "Replaced process with " << argument << ", pid = "
<< pcbTable[runningState]->processId << endl;
}
// Implements the Q command.
void quantum()
{
Instruction instruction;
if (runningState == -1) {
cout << "No processes are running" << endl;
++timestamp;
return;
}
if (cpu.programCounter < (int)cpu.pProgram->size()) {
instruction = (*cpu.pProgram)[cpu.programCounter];
cpu.programCounter++;
} else {
cout << "End of program reached without E operation" <<
endl;
instruction.operation = 'E';
}
switch (instruction.operation) {
case 'S':
set(instruction.intArg);
break;
case 'A':
add(instruction.intArg);
break;
case 'D':
decrement(instruction.intArg);
break;
case 'B':
block();
break;
case 'E':
end();
break;
case 'F':
fork(instruction.intArg);
break;
case 'R':
replace(instruction.stringArg);
break;
}
timestamp++;
// TODO: degug and test
// Increment cpu.timeSliceUsed.
cpu.timeSliceUsed++;
schedule();
}
// Implements the U command.
void unblock()
{
if (!blockedState.empty()) {
int pcbIndex = blockedState.front();
PcbEntry *pcbEntry = pcbTable[pcbIndex];
blockedState.pop_front();
// TODO: debug and test. PHIL << "this process does not
increment the timeStamp, because it comes from Commander?"
// Update the line below to use the correct readyStates
queue.
readyStates[pcbEntry->priority].push_back(pcbIndex);
pcbEntry->state = STATE_READY;
cout << "Unblocked process, pid = " << pcbEntry-
>processId << endl;
}
schedule();
}
void printReadyQue(int *myArray){
for (unsigned int j = 0; j < NUM_PRIORITIES; j++){
if (!readyStates[j].empty()){
cout << "READY STATE PRIORITY " << j << "
QUEUE:n pid | ppid | priority | value | start time | cpu
time used |" << endl;
for (unsigned int i = 0; i < readyStates[j].size();
i++) {
int pcbIndex = readyStates[j][i];
PcbEntry *pcbEntry = pcbTable[pcbIndex];
printf("% *d % *d % *d % *d % *d % *d n" , 7
, pcbEntry->processId , 11, pcbEntry->parentProcessId, 10,
pcbEntry->priority,
10, pcbEntry->value, 10, pcbEntry->startTime, 10,
pcbEntry->timeUsed);
myArray[j] = myArray[j]+1;//increment
prioriety
myArray[4] += pcbEntry->timeUsed;//sum
}
}
}
}
void printProcess(int *myArray){
int myTimeUsed = 0;
const int NUM_STATE = 4;
State myState[NUM_STATE] = {STATE_READY ,
STATE_RUNNING, STATE_BLOCKED, STATE_END};
for (int j =1; j < NUM_STATE; j++){
switch (j) {
case 1:
cout << "RUNNING PROCESSSES:n pid |
ppid | priority | value | start time | cpu time used |" << endl;
break;
case 2:
if (!blockedState.empty())
cout << "BLOCKED PROCESSSES:n
pid | ppid | priority | value | start time | cpu time used |"
<< endl;
break;
case 3:
if (!deadState.empty())
cout << "DEAD PROCESSSES:n pid |
ppid | priority | value | start time | cpu time used |" << endl;
break;
default:
cout << "ERROR!!!!!";
break;
}
for(unsigned int readyEntry = 0; readyEntry <
pcbTable.size(); readyEntry++){
if (pcbTable[readyEntry]->state == myState[j]
){
if (pcbTable[readyEntry]->state ==
STATE_RUNNING)myTimeUsed = pcbTable[runningState]-
>timeUsed+cpu.timeSliceUsed;
else myTimeUsed = pcbTable[readyEntry]-
>timeUsed;
printf("% *d % *d % *d % *d % *d % *d
n" , 7 , pcbTable[readyEntry]->processId , 11,
pcbTable[readyEntry]->parentProcessId, 10,
pcbTable[readyEntry]->priority,
10, pcbTable[readyEntry]-
>value, 10, pcbTable[readyEntry]->startTime, 10,
myTimeUsed);
myArray[pcbTable[readyEntry]-
>priority]++;//increment prioriety
myArray[4] += myTimeUsed;
}
}
}
}
void printPriorieties(int *prioritieList){
cout << endl;
for (int i =0; i<4; i++){
if ( prioritieList[i] != 0)
cout << "number of processes with priority "<< i
<< " is: " << prioritieList[i] << endl;
}
if ((int)timestamp == prioritieList[4]) cout << "nCURRENT
TIME: " << timestamp << " = " << "total CPU TIME USED:
"<< prioritieList[4] << endl;
else cout << "PCB total time does not match this can only
happen if no process was running" << endl;
}
// Implements the P command.
void print()
{
#ifdef ENABLE_REPORTER
pid_t pid;
pid = fork();
if (pid == -1) {
cout << "fork:" << strerror(errno) << endl;
return;
}
if (pid != 0) {
// Wait for the reporter process to exit.
wait(NULL);
return;
}
#endif
#ifdef ENABLE_REPORTER
// TODO: debug and test
//Implement all of the printing logic.
int prioritieList[NUM_PRIORITIES + 1] = {0,0,0,0,0};//+
one for sum[4] counter
cout << "n----------------------------------------------------------
------------" << endl;
//cout << "CURRENT TIME: " << timestamp<< endl;
printReadyQue(prioritieList);//prints the processes in ready
state by que
printProcess(prioritieList);// prints the rest of the processes
printPriorieties(prioritieList);
cout << "-------------------------------------------------------------
---------n"<<endl;
_exit(EXIT_SUCCESS);
#endif
}
// Function that implements the process manager.
int runProcessManager(int fileDescriptor)
{
PcbEntry *pcbEntry = new PcbEntry();
// Attempt to create the init process.
if
(!createProgram("Users/JGilchrist/Desktop/ECET365/week1/" ,
pcbEntry->program)) {
delete pcbEntry;
return EXIT_FAILURE;
}
pcbEntry->processId = (int)pcbTable.size();
pcbEntry->parentProcessId = -1;
pcbEntry->programCounter = 0;
pcbEntry->value = 0;
pcbEntry->priority = 0;
pcbEntry->state = STATE_RUNNING;
pcbEntry->startTime = 0;
pcbEntry->timeUsed = 0;
pcbTable.push_back(pcbEntry);
runningState = pcbEntry->processId;
cout << "Running init process, pid = " << pcbEntry-
>processId << endl;
cpu.pProgram = &(pcbEntry->program);
cpu.programCounter = pcbEntry->programCounter;
cpu.value = pcbEntry->value;
timestamp = 0;
double avgTurnaroundTime = 0;
// Loop until a 'T' is read, then terminate.
char ch;
do {
// Read a command character from the pipe.
if (read(fileDescriptor, &ch, sizeof(ch)) != sizeof(ch)) {
// Assume the parent process exited, breaking the pipe.
break;
}
// Ignore whitespace characters.
if (isspace(ch)) {
continue;
}
// Convert commands to a common case so both lower and
uppercase
// commands can be used.
ch = toupper(ch);
switch (ch) {
case 'Q':
quantum();
break;
case 'U':
unblock();
break;
case 'P':
print();
break;
case 'T':
if (numTerminatedProcesses != 0) {
avgTurnaroundTime = cumulativeTimeDiff
/ (double)numTerminatedProcesses;
}
cout << "The average turnaround time is " <<
avgTurnaroundTime
<< "." << endl;
break;
default:
cout << "Unknown command, " << ch << endl;
break;
}
} while (ch != 'T');
// Cleanup any remaining PCB entries.
for (vector<PcbEntry *>::iterator it = pcbTable.begin();
it != pcbTable.end(); it++) {
delete *it;
}
pcbTable.clear();
return EXIT_SUCCESS;
}
// Main function that implements the commander.
int main(int argc, char *argv[])
{
#ifdef ENABLE_COMMANDER
int pipeDescriptors[2];
pid_t processMgrPid;
char ch;
int result;
// Create a pipe.
if (pipe(pipeDescriptors) == -1) {
// Print an error message to help debugging.
cout << "pipe: " << strerror(errno) << endl;
return EXIT_FAILURE;
}
// Create the process manager process.
processMgrPid = fork();
if (processMgrPid == -1) {
// Print an error message to help debugging.
cout << "fork: " << strerror(errno) << endl;
return EXIT_FAILURE;
}
if (processMgrPid == 0) {
// The process manager process is running.
// Close the unused write end of the pipe for the process
manager
// process.
close(pipeDescriptors[1]);
// Run the process manager.
result = runProcessManager(pipeDescriptors[0]);
// Close the read end of the pipe for the process manager
process (for
// cleanup purposes).
close(pipeDescriptors[0]);
_exit(result);
} else {
// The commander process is running.
// Close the unused read end of the pipe for the
commander process.
close(pipeDescriptors[0]);
// Loop until a 'T' is written or until the pipe is broken.
do {
sleep(1);
cout << "Input a command: ";
// Read a command character from the standard input.
cin >> ch;
cout << endl;
// Pass commands to the process manager process via
the pipe.
if (write(pipeDescriptors[1], &ch, sizeof(ch)) !=
sizeof(ch)) {
// Assume the child process exited, breaking the pipe.
break;
}
} while (ch != 'T');
// Wait for the process manager to exit.
wait(&result);
// Close the write end of the pipe for the commander
process (for
// cleanup purposes).
close(pipeDescriptors[1]);
}
return result;
#else
// Run the Process Manager directly.
return runProcessManager(fileno(stdin));
#endif
}
lab3_7.png
Lab-7 Explanation
1- An Install and README file:
A single file that gives a brief description of the program, how
to install it, how to execute it (you don't really need to explain
commands etc., just how to start the program), and maybe
references to any other relevant information (i.e. for more
information consult the user guide). The overall guidance here
is keeping it short and to the point. This is pretty much what
most have you have already been providing to me.
2- A User Guide:
You need to describe the program's behavior (what the user
should expect to see), what the commands are and their
purposes. You probably want to describe the format of the
"program" files that the simulator runs. Almost all the
information you need is on the iLab page itself, except you
should describe anything about your program that may be
special, different, or not immediately obvious to a user. The
overall guidance here is to accurately describe how to use all
aspects of the program without talking about how the program
works or is implemented (unless it is absolutely essential to
understand how to use the program).
3- A System Programming Guide:
This guide will explain the design and structure of the program
itself. Describe how it works on an internal level. This is a
guide a programmer might use, so you want to consider the use
cases that relate to a programmer. What if a programmer wanted
to add a new command? How about a new program operation?
The information contained within should give a programmer a
good idea of which parts of the program provide specific
functionality, and how that functionality is implemented. You
don't want to go down to the level of describing the code itself
in words, but you do want to describe any important algorithms
in detail, and at least generalize how things work. The overall
guidance here is to leave out details about how to run or use the
program, and just talk about how the program actually does its
job.
4- Manual pages:
This is mostly going to be a reformatting of the Users Guide.
You should follow the format of a typical Unix/Linux man page
(Google around to find some examples). I would include most
or all of the things in the User’s Guide.

More Related Content

Similar to 1) According to Cudd and Jones, the term sexism refers to which .docx

Feldo: Function Event Listing and Dynamic Observing for Detecting and Prevent...
Feldo: Function Event Listing and Dynamic Observing for Detecting and Prevent...Feldo: Function Event Listing and Dynamic Observing for Detecting and Prevent...
Feldo: Function Event Listing and Dynamic Observing for Detecting and Prevent...Tzung-Bi Shih
 
1. Login to vdi.umuc.edu2. Open the Cyber Programs Desktop by .docx
1. Login to vdi.umuc.edu2. Open the Cyber Programs Desktop by .docx1. Login to vdi.umuc.edu2. Open the Cyber Programs Desktop by .docx
1. Login to vdi.umuc.edu2. Open the Cyber Programs Desktop by .docxjeremylockett77
 
Exampleessays. . How to write an informative essay
Exampleessays. . How to write an informative essayExampleessays. . How to write an informative essay
Exampleessays. . How to write an informative essayJenny Reese
 
Report Card making BY Mitul Patel
Report Card making BY Mitul PatelReport Card making BY Mitul Patel
Report Card making BY Mitul PatelMitul Patel
 
C Best and Worst Practices in Embedded
C Best and Worst Practices in EmbeddedC Best and Worst Practices in Embedded
C Best and Worst Practices in EmbeddedGlobalLogic Ukraine
 
Introduction Definition In Writing. Definition Of Introdu
Introduction Definition In Writing. Definition Of IntroduIntroduction Definition In Writing. Definition Of Introdu
Introduction Definition In Writing. Definition Of IntroduNaomi Hansen
 
Polygamy Essay Outline
Polygamy Essay OutlinePolygamy Essay Outline
Polygamy Essay OutlineAmanda Cote
 
Threading Is Not A Model
Threading Is Not A ModelThreading Is Not A Model
Threading Is Not A Modelguest2a5acfb
 
100 objective question eis
100 objective question eis100 objective question eis
100 objective question eisgajani121
 
Masters bioinfo 2013-11-14-15
Masters bioinfo 2013-11-14-15Masters bioinfo 2013-11-14-15
Masters bioinfo 2013-11-14-15Yannick Wurm
 
Fundamentals of programming angeli
Fundamentals of programming angeliFundamentals of programming angeli
Fundamentals of programming angelibergonio11339481
 
Assignment unix & shell programming
Assignment  unix  & shell programmingAssignment  unix  & shell programming
Assignment unix & shell programmingMohit Aggarwal
 
Activities - Modal Verbs.pdf
Activities - Modal Verbs.pdfActivities - Modal Verbs.pdf
Activities - Modal Verbs.pdfCintia Santos
 
How Does A Persuasive Essay Look Like. Kolobbo
How Does A Persuasive Essay Look Like. KolobboHow Does A Persuasive Essay Look Like. Kolobbo
How Does A Persuasive Essay Look Like. KolobboSamantha Jones
 
Comp 129 Enthusiastic Study / snaptutorial.com
Comp 129 Enthusiastic Study / snaptutorial.comComp 129 Enthusiastic Study / snaptutorial.com
Comp 129 Enthusiastic Study / snaptutorial.comStephenson41
 
designpatterns_blair_upe.ppt
designpatterns_blair_upe.pptdesignpatterns_blair_upe.ppt
designpatterns_blair_upe.pptbanti43
 

Similar to 1) According to Cudd and Jones, the term sexism refers to which .docx (20)

Feldo: Function Event Listing and Dynamic Observing for Detecting and Prevent...
Feldo: Function Event Listing and Dynamic Observing for Detecting and Prevent...Feldo: Function Event Listing and Dynamic Observing for Detecting and Prevent...
Feldo: Function Event Listing and Dynamic Observing for Detecting and Prevent...
 
1. Login to vdi.umuc.edu2. Open the Cyber Programs Desktop by .docx
1. Login to vdi.umuc.edu2. Open the Cyber Programs Desktop by .docx1. Login to vdi.umuc.edu2. Open the Cyber Programs Desktop by .docx
1. Login to vdi.umuc.edu2. Open the Cyber Programs Desktop by .docx
 
Exampleessays. . How to write an informative essay
Exampleessays. . How to write an informative essayExampleessays. . How to write an informative essay
Exampleessays. . How to write an informative essay
 
Report Card making BY Mitul Patel
Report Card making BY Mitul PatelReport Card making BY Mitul Patel
Report Card making BY Mitul Patel
 
C Best and Worst Practices in Embedded
C Best and Worst Practices in EmbeddedC Best and Worst Practices in Embedded
C Best and Worst Practices in Embedded
 
Introduction Definition In Writing. Definition Of Introdu
Introduction Definition In Writing. Definition Of IntroduIntroduction Definition In Writing. Definition Of Introdu
Introduction Definition In Writing. Definition Of Introdu
 
C programming day#1
C programming day#1C programming day#1
C programming day#1
 
Polygamy Essay Outline
Polygamy Essay OutlinePolygamy Essay Outline
Polygamy Essay Outline
 
Clean code
Clean codeClean code
Clean code
 
Threading Is Not A Model
Threading Is Not A ModelThreading Is Not A Model
Threading Is Not A Model
 
100 objective question eis
100 objective question eis100 objective question eis
100 objective question eis
 
Masters bioinfo 2013-11-14-15
Masters bioinfo 2013-11-14-15Masters bioinfo 2013-11-14-15
Masters bioinfo 2013-11-14-15
 
Fundamentals of programming angeli
Fundamentals of programming angeliFundamentals of programming angeli
Fundamentals of programming angeli
 
Assignment unix & shell programming
Assignment  unix  & shell programmingAssignment  unix  & shell programming
Assignment unix & shell programming
 
Virus lab
Virus labVirus lab
Virus lab
 
Activities - Modal Verbs.pdf
Activities - Modal Verbs.pdfActivities - Modal Verbs.pdf
Activities - Modal Verbs.pdf
 
Facebook
FacebookFacebook
Facebook
 
How Does A Persuasive Essay Look Like. Kolobbo
How Does A Persuasive Essay Look Like. KolobboHow Does A Persuasive Essay Look Like. Kolobbo
How Does A Persuasive Essay Look Like. Kolobbo
 
Comp 129 Enthusiastic Study / snaptutorial.com
Comp 129 Enthusiastic Study / snaptutorial.comComp 129 Enthusiastic Study / snaptutorial.com
Comp 129 Enthusiastic Study / snaptutorial.com
 
designpatterns_blair_upe.ppt
designpatterns_blair_upe.pptdesignpatterns_blair_upe.ppt
designpatterns_blair_upe.ppt
 

More from dorishigh

Cyber War versus Cyber Realities Cyber War v.docx
Cyber War versus Cyber Realities Cyber War v.docxCyber War versus Cyber Realities Cyber War v.docx
Cyber War versus Cyber Realities Cyber War v.docxdorishigh
 
Cyber terrorism, by definition, is the politically motivated use.docx
Cyber terrorism, by definition, is the politically motivated use.docxCyber terrorism, by definition, is the politically motivated use.docx
Cyber terrorism, by definition, is the politically motivated use.docxdorishigh
 
Cyber Security ThreatsYassir NourDr. Fonda IngramETCS-690 .docx
Cyber Security ThreatsYassir NourDr. Fonda IngramETCS-690 .docxCyber Security ThreatsYassir NourDr. Fonda IngramETCS-690 .docx
Cyber Security ThreatsYassir NourDr. Fonda IngramETCS-690 .docxdorishigh
 
Cyber Security in Industry 4.0Cyber Security in Industry 4.0 (.docx
Cyber Security in Industry 4.0Cyber Security in Industry 4.0 (.docxCyber Security in Industry 4.0Cyber Security in Industry 4.0 (.docx
Cyber Security in Industry 4.0Cyber Security in Industry 4.0 (.docxdorishigh
 
Cyber Security and the Internet of ThingsVulnerabilities, T.docx
Cyber Security and the Internet of ThingsVulnerabilities, T.docxCyber Security and the Internet of ThingsVulnerabilities, T.docx
Cyber Security and the Internet of ThingsVulnerabilities, T.docxdorishigh
 
Cyber Security Gone too farCarlos Diego LimaExce.docx
Cyber Security Gone too farCarlos Diego LimaExce.docxCyber Security Gone too farCarlos Diego LimaExce.docx
Cyber Security Gone too farCarlos Diego LimaExce.docxdorishigh
 
CW 1R Checklist and Feedback Sheet Student Copy Go through this.docx
CW 1R Checklist and Feedback Sheet Student Copy Go through this.docxCW 1R Checklist and Feedback Sheet Student Copy Go through this.docx
CW 1R Checklist and Feedback Sheet Student Copy Go through this.docxdorishigh
 
CW 1 Car Industry and AIby Victoria StephensonSubmission.docx
CW 1 Car Industry and AIby Victoria StephensonSubmission.docxCW 1 Car Industry and AIby Victoria StephensonSubmission.docx
CW 1 Car Industry and AIby Victoria StephensonSubmission.docxdorishigh
 
CWTS CWFT Module 7 Chapter 2 Eco-maps 1 ECO-MAPS .docx
CWTS CWFT Module 7 Chapter 2 Eco-maps 1 ECO-MAPS .docxCWTS CWFT Module 7 Chapter 2 Eco-maps 1 ECO-MAPS .docx
CWTS CWFT Module 7 Chapter 2 Eco-maps 1 ECO-MAPS .docxdorishigh
 
Cw2 Marking Rubric Managerial Finance0Fail2(1-29) Fail.docx
Cw2 Marking Rubric Managerial Finance0Fail2(1-29) Fail.docxCw2 Marking Rubric Managerial Finance0Fail2(1-29) Fail.docx
Cw2 Marking Rubric Managerial Finance0Fail2(1-29) Fail.docxdorishigh
 
Cyber AttacksProtecting National Infrastructure, 1st ed.Ch.docx
Cyber AttacksProtecting National Infrastructure, 1st ed.Ch.docxCyber AttacksProtecting National Infrastructure, 1st ed.Ch.docx
Cyber AttacksProtecting National Infrastructure, 1st ed.Ch.docxdorishigh
 
CVPSales price per unit$75.00Variable Cost per unit$67.00Fixed C.docx
CVPSales price per unit$75.00Variable Cost per unit$67.00Fixed C.docxCVPSales price per unit$75.00Variable Cost per unit$67.00Fixed C.docx
CVPSales price per unit$75.00Variable Cost per unit$67.00Fixed C.docxdorishigh
 
CYB207 v2Wk 4 – Assignment TemplateCYB205 v2Page 2 of 2.docx
CYB207 v2Wk 4 – Assignment TemplateCYB205 v2Page 2 of 2.docxCYB207 v2Wk 4 – Assignment TemplateCYB205 v2Page 2 of 2.docx
CYB207 v2Wk 4 – Assignment TemplateCYB205 v2Page 2 of 2.docxdorishigh
 
CUSTOMERSERVICE-TRAINIGPROGRAM 2 TA.docx
CUSTOMERSERVICE-TRAINIGPROGRAM 2  TA.docxCUSTOMERSERVICE-TRAINIGPROGRAM 2  TA.docx
CUSTOMERSERVICE-TRAINIGPROGRAM 2 TA.docxdorishigh
 
Customer Service Test (Chapter 6 - 10)Name Multiple Choice.docx
Customer Service Test (Chapter 6 - 10)Name Multiple Choice.docxCustomer Service Test (Chapter 6 - 10)Name Multiple Choice.docx
Customer Service Test (Chapter 6 - 10)Name Multiple Choice.docxdorishigh
 
Customer Value Funnel Questions1. Identify the relevant .docx
Customer Value Funnel Questions1. Identify the relevant .docxCustomer Value Funnel Questions1. Identify the relevant .docx
Customer Value Funnel Questions1. Identify the relevant .docxdorishigh
 
Customer service is something that we have all heard of and have som.docx
Customer service is something that we have all heard of and have som.docxCustomer service is something that we have all heard of and have som.docx
Customer service is something that we have all heard of and have som.docxdorishigh
 
Customer requests areProposed Cloud Architecture (5 pages n.docx
Customer requests areProposed Cloud Architecture (5 pages n.docxCustomer requests areProposed Cloud Architecture (5 pages n.docx
Customer requests areProposed Cloud Architecture (5 pages n.docxdorishigh
 
Customer Relationship Management Presented ByShan Gu Cris.docx
Customer Relationship Management Presented ByShan Gu Cris.docxCustomer Relationship Management Presented ByShan Gu Cris.docx
Customer Relationship Management Presented ByShan Gu Cris.docxdorishigh
 
Custom Vans Inc. Custom Vans Inc. specializes in converting st.docx
Custom Vans Inc. Custom Vans Inc. specializes in converting st.docxCustom Vans Inc. Custom Vans Inc. specializes in converting st.docx
Custom Vans Inc. Custom Vans Inc. specializes in converting st.docxdorishigh
 

More from dorishigh (20)

Cyber War versus Cyber Realities Cyber War v.docx
Cyber War versus Cyber Realities Cyber War v.docxCyber War versus Cyber Realities Cyber War v.docx
Cyber War versus Cyber Realities Cyber War v.docx
 
Cyber terrorism, by definition, is the politically motivated use.docx
Cyber terrorism, by definition, is the politically motivated use.docxCyber terrorism, by definition, is the politically motivated use.docx
Cyber terrorism, by definition, is the politically motivated use.docx
 
Cyber Security ThreatsYassir NourDr. Fonda IngramETCS-690 .docx
Cyber Security ThreatsYassir NourDr. Fonda IngramETCS-690 .docxCyber Security ThreatsYassir NourDr. Fonda IngramETCS-690 .docx
Cyber Security ThreatsYassir NourDr. Fonda IngramETCS-690 .docx
 
Cyber Security in Industry 4.0Cyber Security in Industry 4.0 (.docx
Cyber Security in Industry 4.0Cyber Security in Industry 4.0 (.docxCyber Security in Industry 4.0Cyber Security in Industry 4.0 (.docx
Cyber Security in Industry 4.0Cyber Security in Industry 4.0 (.docx
 
Cyber Security and the Internet of ThingsVulnerabilities, T.docx
Cyber Security and the Internet of ThingsVulnerabilities, T.docxCyber Security and the Internet of ThingsVulnerabilities, T.docx
Cyber Security and the Internet of ThingsVulnerabilities, T.docx
 
Cyber Security Gone too farCarlos Diego LimaExce.docx
Cyber Security Gone too farCarlos Diego LimaExce.docxCyber Security Gone too farCarlos Diego LimaExce.docx
Cyber Security Gone too farCarlos Diego LimaExce.docx
 
CW 1R Checklist and Feedback Sheet Student Copy Go through this.docx
CW 1R Checklist and Feedback Sheet Student Copy Go through this.docxCW 1R Checklist and Feedback Sheet Student Copy Go through this.docx
CW 1R Checklist and Feedback Sheet Student Copy Go through this.docx
 
CW 1 Car Industry and AIby Victoria StephensonSubmission.docx
CW 1 Car Industry and AIby Victoria StephensonSubmission.docxCW 1 Car Industry and AIby Victoria StephensonSubmission.docx
CW 1 Car Industry and AIby Victoria StephensonSubmission.docx
 
CWTS CWFT Module 7 Chapter 2 Eco-maps 1 ECO-MAPS .docx
CWTS CWFT Module 7 Chapter 2 Eco-maps 1 ECO-MAPS .docxCWTS CWFT Module 7 Chapter 2 Eco-maps 1 ECO-MAPS .docx
CWTS CWFT Module 7 Chapter 2 Eco-maps 1 ECO-MAPS .docx
 
Cw2 Marking Rubric Managerial Finance0Fail2(1-29) Fail.docx
Cw2 Marking Rubric Managerial Finance0Fail2(1-29) Fail.docxCw2 Marking Rubric Managerial Finance0Fail2(1-29) Fail.docx
Cw2 Marking Rubric Managerial Finance0Fail2(1-29) Fail.docx
 
Cyber AttacksProtecting National Infrastructure, 1st ed.Ch.docx
Cyber AttacksProtecting National Infrastructure, 1st ed.Ch.docxCyber AttacksProtecting National Infrastructure, 1st ed.Ch.docx
Cyber AttacksProtecting National Infrastructure, 1st ed.Ch.docx
 
CVPSales price per unit$75.00Variable Cost per unit$67.00Fixed C.docx
CVPSales price per unit$75.00Variable Cost per unit$67.00Fixed C.docxCVPSales price per unit$75.00Variable Cost per unit$67.00Fixed C.docx
CVPSales price per unit$75.00Variable Cost per unit$67.00Fixed C.docx
 
CYB207 v2Wk 4 – Assignment TemplateCYB205 v2Page 2 of 2.docx
CYB207 v2Wk 4 – Assignment TemplateCYB205 v2Page 2 of 2.docxCYB207 v2Wk 4 – Assignment TemplateCYB205 v2Page 2 of 2.docx
CYB207 v2Wk 4 – Assignment TemplateCYB205 v2Page 2 of 2.docx
 
CUSTOMERSERVICE-TRAINIGPROGRAM 2 TA.docx
CUSTOMERSERVICE-TRAINIGPROGRAM 2  TA.docxCUSTOMERSERVICE-TRAINIGPROGRAM 2  TA.docx
CUSTOMERSERVICE-TRAINIGPROGRAM 2 TA.docx
 
Customer Service Test (Chapter 6 - 10)Name Multiple Choice.docx
Customer Service Test (Chapter 6 - 10)Name Multiple Choice.docxCustomer Service Test (Chapter 6 - 10)Name Multiple Choice.docx
Customer Service Test (Chapter 6 - 10)Name Multiple Choice.docx
 
Customer Value Funnel Questions1. Identify the relevant .docx
Customer Value Funnel Questions1. Identify the relevant .docxCustomer Value Funnel Questions1. Identify the relevant .docx
Customer Value Funnel Questions1. Identify the relevant .docx
 
Customer service is something that we have all heard of and have som.docx
Customer service is something that we have all heard of and have som.docxCustomer service is something that we have all heard of and have som.docx
Customer service is something that we have all heard of and have som.docx
 
Customer requests areProposed Cloud Architecture (5 pages n.docx
Customer requests areProposed Cloud Architecture (5 pages n.docxCustomer requests areProposed Cloud Architecture (5 pages n.docx
Customer requests areProposed Cloud Architecture (5 pages n.docx
 
Customer Relationship Management Presented ByShan Gu Cris.docx
Customer Relationship Management Presented ByShan Gu Cris.docxCustomer Relationship Management Presented ByShan Gu Cris.docx
Customer Relationship Management Presented ByShan Gu Cris.docx
 
Custom Vans Inc. Custom Vans Inc. specializes in converting st.docx
Custom Vans Inc. Custom Vans Inc. specializes in converting st.docxCustom Vans Inc. Custom Vans Inc. specializes in converting st.docx
Custom Vans Inc. Custom Vans Inc. specializes in converting st.docx
 

Recently uploaded

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 

Recently uploaded (20)

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 

1) According to Cudd and Jones, the term sexism refers to which .docx

  • 1. 1) According to Cudd and Jones, the term 'sexism' refers to which of the following? a. The unjustified systemic disadvantage faced by women. b. Anything that involves treating men and women differently. c. Anything that makes women less well-off than men. d. The widely held belief that women are inferior to men and deserve less. 2) According to Frye, what is a double bind? a) It is a situation where choices are reduced to a few, and all of those choices have bad outcomes. b) The double bind is a kind of knot used by sailors. c) It is a situation where the choices of an oppressor bind the oppressed. d) It is situation where one is bound by multiple social forces and has no choice in what to do. 3) What is the purpose of Frye's discussion of the custom of men opening doors for women? a) To illustrate an example of a double bind. b) To show that some customs based on gender are okay when helpful. c) To show that if a man ever opens a door for a woman, he is being sexist. d) To illustrate the difference between macroscopic and microscopic modes of analysis. 4) Which of the following best characterizes the role of sex in advertising according to Bordo? a) Sex doesn't really play a noticeable role in advertising, which is about getting information about a product into the world. b) Women's eating serves as a metaphor for sexual experience, while men's sexual appetite is a metaphor for their hunger. c) Sexual desire is natural for men so it is openly depicted, but
  • 2. for women such desire must be hidden through subtle hints. d) Sex sells, so putting attractive members of the opposite sex near product will lead to positive attitudes toward the product. 5) Which of the following possible causes of poverty does "The End of Poverty" emphasize? a) Colonialism as it transformed from political to contemporary economic forms b) Political corruption in countries with developing economies c) Bad education and work habits among citizens of developing nations d) Greed on the part of owners of major companies 6) "The Debt of Dictators" suggests that the US and other developed nations had which of the following roles in creating the debt of dictators? a) Developed nations were largely uninvolved in the debt of dictators b) Developed nations were usually forced to loan money to dictators for humanitarian reasons c) Developed nations willingly lent money to corrupt dictators because it was profitable to do so d) Developed nations borrowed money from dictators to fund extravagant social welfare programs 7) Which of the following best characterizes Pogge's thesis? a) Most people in the US are actively harming those impoverished around the world, and consequently have an obligation to alleviate poverty b) Most people in the US can help the impoverished around the world at little cost; while they are not obligated to do so, they would be more virtuous if they did so c) Most people in the US are uninvolved in global injustice, and are not in a position to do anything about it d) Most people in the US are not actively harming the impoverished, but can still help them at little cost to
  • 3. themselves, therefore have an obligation to help them 8) What is an intermediate duty according to Pogge? a) An Intermediate duty occupies the mean between excess and deficiency in the character of the agent who acts b) Between positive and negative duties, intermediate duty requires action by agents, but is grounded in their duty not to harm others c) An intermediate duty is one that balances the costs against the expected benefits of an action d) Between perfect and imperfect duties, intermediate duties are always obligatory, but only under certain circumstances JGilchrist_lab1 Code.txt /* * File: week1ECET360.cpp * Author: JGilchrist * * Created on November 5, 2013, 8:20 PM */ #pragma GCC diagnostic ignored "-Wwrite-strings" //compiler directive? Cplusplus.com #include <cstdlib> // for EXIT_SUCCESS and EXIT_FAILURE
  • 4. #include <iostream> // for cout, endl, and cin #include <stdio.h> #include <sys/wait.h> // for wait() #include <unistd.h> // for pipe(), read(), write(), close(), fork(), and _exit() using namespace std; /*************************************** *Used from the the partial code given ****************************************/ /* Commander Process: */ int main(int argc, char** argv) { int result = 0; int pfd[2]; pid_t cpid; //cpid of type integer defined types.h //Via Paul Nichols bool parentLoop = true;//control variable for write loop, break?CPlusplus.con char userInput; //user input
  • 5. if (pipe(pfd) == -1) {//creating the pipe perror("pipe failed"); exit(EXIT_FAILURE); } //fork a child process after the pipe is made so they both have same PFD via http://www.advancedlinuxprogramming.com/alp- folder/alp-ch03-processes.pdf cpid = fork(); if (cpid == -1) {//if fork returned error exit perror("fork failed"); //via Paul Nichols exit(EXIT_FAILURE); } //wait for a second so child doesnt write over parent sleep(1);//linux sleep 1 second if using windows Sleep(milliseconds) if(cpid != 0) { //this is the parent-->Commander process********************************************** *** close(pfd[0]); //closing read end on parent...parent only writes
  • 6. cout << "commands are 'Q', 'U', 'P', or 'T' to quit"<<endl; while(parentLoop == true){ sleep(1);//linux sleep 1 second if using windows Sleep(milliseconds) cout << "enter a command: "; cin >> userInput; cout << endl; // cout for the user input if((userInput=='Q') || (userInput=='U')||(userInput=='P')){ /************************************************ ************************************ * The commander process accepts four commands: Used from the ILab Tab * 1. Q: End of one unit of time. * 2. U: Unblock the first simulated process in blocked queue. * 3. P: Print the current state of the system. * 4. T: Print the average turn around time, and terminate the system. ************************************************
  • 7. *************************************/ //write info to pipe if(write(pfd[1], &userInput, sizeof(userInput)) < 0) exit(EXIT_FAILURE); //sleep(.5);//linux sleep 1 second if using windows Sleep(milliseconds) } else if(userInput == 'T'){ cout << "user input is T...Terminating parent" << endl; parentLoop = false; if(write(pfd[1], &userInput, 1) < 0){ perror("pipe write failed"); exit(EXIT_FAILURE); } } else { cout << "invalid input, please enter values of 'Q', 'U', 'P', or 'T' to quitn" << endl;
  • 8. } } cout << "waiting for child process to close.."<<endl; close(pfd[1]);//close write end of pipe wait(NULL);// wait for child to close exit(EXIT_SUCCESS); }//end of parent process code************************************************* *************************** else { //this is child--swap--> Process Manager process //execl( project_manager_loc , "Project_Manager", argv[1], &string1[0], (char *) 0); close(pfd[1]);//close write end of pipe char *project_manager_loc = "./Project_Manager"; char string1[12]; // A 32 bit number can't take more than 11 characters, + a terminating 0 snprintf(string1,12,"%i",pfd[0]); // Copy the file descriptor into a string
  • 9. char *args_1[] = {"Project_Manager", argv[0], &string1[0], (char *) 0}; execve( project_manager_loc , args_1, NULL); cout << "Error executing child...can not open" << endl; close(pfd[0]); cout << "exiting" << endl; }//end process _exit(result); } Archive created by free jZip.url [InternetShortcut] URL=http://www.jzip.com/archive_link JGilchrist_Ilab2_execution_file.txt /* * File: week1ECET360Execution.cpp * Author: JGilchrist * Tutor: Paul Nichols
  • 10. * References used: http://www.advancedlinuxprogramming.com/alp-folder/alp- ch03-processes.pdf * cplusplus.com, stackedoverflow.com * Created on November 10, 2013, 6:20 PM */ #include <cctype> // for toupper() #include <cstdlib> // for EXIT_SUCCESS and EXIT_FAILURE #include <cstring> // for strerror() #include <cerrno> // for errno #include <deque> // for deque (used for ready and blocked queues) #include <fstream> // for ifstream (used for reading simulated process programs) #include <iostream> // for cout, endl, and cin #include <sstream> // for stringstream (for parsing simulated process programs) #include <sys/wait.h> // for wait() #include <unistd.h> // for pipe(), read(), write(), close(), fork(), and _exit()
  • 11. #include <vector> // for vector (used for PCB table) #include <stdexcept> // std::out_of_range using namespace std; class Instruction {//file instruction format public: char operation; int intArg; string stringArg; }; /**************************************************** ***************************************************** * Cpu is used to simulate the execution of a simulated process that is in running state. * It should include data members to store a pointer to the program array, current program counter value, * integer value, and time slice of that simulated process. In addition, it should store the number of * time units used so far in the current time slice.
  • 12. ***************************************************** ****************************************************/ class Cpu { public: vector<Instruction> *pProgram;//this is a pointer to PcbEntry.program int programCounter; int value; int timeSlice;//curent time slice int timeSliceUsed;//time units used so far in current time slice }; enum State {//curent state of pcbEntry STATE_READY, STATE_RUNNING, STATE_BLOCKED };
  • 13. class PcbEntry {//class of values to save in PCB table public: int processId; int parentProcessId; vector<Instruction> program;//program is a list Instruction class objects(char operation, int, string) unsigned int programCounter; int value; unsigned int priority; State state; unsigned int startTime; // For iLab 3, unused for iLab 2 unsigned int timeUsed; // For iLab 3, unused for iLab 2 }; unsigned int timestamp = 0; // The current simulation time. Cpu cpu; // The current CPU state. // For the states below, -1 indicates empty (since it is an invalid index).***see State description
  • 14. /**************************************************** ************************************************* * RunningState stores the PcbTable index of the currently running simulated process. ***************************************************** **************************************************/ int runningState = -1; // The index of the running process in the PCB table. /**************************************************** ************************************************ * ReadyState stores all simulated processes (PcbTable indices) that are ready to run. * This can be implemented using a queue or priority queue data structure. ***************************************************** ***********************************************/ deque<int> readyState; // A queue of PCB indices for ready processes.(index) /**************************************************** *************************************************
  • 15. * BlockedState stores all processes (PcbTable indices) that are currently blocked. * This can be implemented using a queue data structure. ***************************************************** **************************************************/ deque<int> blockedState; // A queue of PCB indices for blocked processes. // In this implementation, we'll never explicitly clear PCB entries and the // index in the table will always be the process ID. These choices waste memory, // but since this program is just a simulation it the easiest approach. // Additionally, debugging is simpler since table slots and process IDs are // never re-used. /**************************************************** ***************************************************** * PcbTable is an array with one entry for every simulated process that hasn't finished its execution yet. * Each entry should include data members to store process id, parent process id, a pointer to program counter
  • 16. * value (initially 0), integer value, priority, state, start time, and CPU time used so far. ***************************************************** ***************************************************/ vector<PcbEntry *> pcbTable; double cumulativeTimeDiff = 0; int numTerminatedProcesses = 0; // Sadly, C++ has no built-in way to trim strings: string& trim(string &argument) { string whitespace(" tnvfr"); size_t found = argument.find_last_not_of(whitespace); if (found != string::npos) { argument.erase(found + 1); argument.erase(0, argument.find_first_not_of(whitespace)); } else {
  • 17. argument.clear(); // all whitespace } return argument; } bool createProgram(const string &filename, vector<Instruction> &program) { cout << "running creatProgram process " << endl; ifstream file; //open a stream to "init" named file int lineNum = 0; file.open(filename.c_str()); if (!file.is_open()) { cout << " file open: Error opening file " << filename << endl; return false; }
  • 18. while (file.good()) {//------------------- process init file ------- ------------------------------------- string line; getline(file, line); cout << " read from " << filename.c_str() << " : " << line << endl; trim(line); if (line.size() > 0) { Instruction instruction; instruction.operation = toupper(line[0]); instruction.stringArg = trim(line.erase(0, 1)); stringstream argStream(instruction.stringArg); switch (instruction.operation) { case 'S': // Integer argument. case 'A': // Integer argument.
  • 19. case 'D': // Integer argument. case 'F': // Integer argument. if (!(argStream >> instruction.intArg)) { cout << filename << ":" << lineNum << " - Invalid integer argument " << instruction.stringArg << " for " << instruction.operation << " operation" << endl; file.close(); return false; } break; case 'B': // No argument. case 'E': // No argument. break; case 'R': // String argument. // Note that since the string is trimmed on both ends, // filenames with leading or trailing whitespace
  • 20. (unlikely) // will not work. if (instruction.stringArg.size() == 0) { cout << filename << ":" << lineNum << " - Missing string argument" << endl; file.close(); return false; } break; default: cout << filename << ":" << lineNum << " - Invalid operation, " << instruction.operation << endl; file.close(); return false; }
  • 21. program.push_back(instruction); } lineNum++; }//-------------------------------- finished processing the file --- ----------------------/ file.close(); return true; } /**************************************************** ***************************************** * Instructions S, A and D update the integer value stored in Cpu. ***************************************************** ***************************************/ void set(int value){ cpu.value = value; cout << "running set process...setting cpu value to "<< cpu.value << endl;
  • 22. } void add(int value){ cpu.value = cpu.value + value; cout << "running +add process new cpu value = "<< cpu.value << endl; } void decrement(int value){ cpu.value = cpu.value - value; cout << "running -decrement process new cpu value = " << cpu.value << endl; } // Performs scheduling. void schedule() { cout << "running schedule process "; cout << " PID = " << runningState << " "; // 1. Return if there is still a processing running (runningState != -1).
  • 23. if (runningState == -1 && !readyState.empty()){//nothing running and process is in queue // 2. Get a new process to run, if possible, from the readystate queue. runningState = readyState.front();//retrieve the index of the pcbTable that is ready to run cout << "...loading new process from que pid is " << runningState << endl; readyState.pop_front();//remove it from queue push back-->pop front; // 3. If we were able to get a new process to run: // a. Mark the processing as running (update new process's PCB state) //***warning*** if pcbTable[location] does not exist you are exited!!!! pcbTable[runningState]->state = STATE_RUNNING; //cout << "SET NEW RUNNING STATE" << endl; // b. Update the CPU structure with the PCB entry details (program, // program counter, value, etc.) cpu.pProgram = &pcbTable[runningState]- >program;//the whole list
  • 24. //cout << "SET NEW PROGRAM" << endl; cpu.programCounter = pcbTable[runningState]- >programCounter; //cout << "SET NEW PROGRAM COUNTER" << endl; cpu.value = pcbTable[runningState]->value; //cout << "SET NEW VALUE" << endl; cpu.timeSlice = pcbTable[runningState]->startTime; //cout << "SET NEW TIMESLICE" << endl; cpu.timeSliceUsed = pcbTable[runningState]- >timeUsed; } else if ((runningState == -1)&& (readyState.empty())) cout << "nothing in queue and nothing running blocked state = " << blockedState.size()<< " try and Unblock "<< endl; else cout << "...process is running" << endl; } /**************************************************** ************************************** * Instruction B moves the currently running simulated process
  • 25. to the blocked state * and moves a process from the ready state to the running state. * This will result in a context switch. ***************************************************** ************************************/ void block() { cout << "running block process " << endl; // 1. Add the PCB index of the running process (stored in runningState) to // the blocked queue. blockedState.push_back(runningState);//push back pull front // 2. Update the process's PCB entry // a. Change the PCB's state to blocked. // b. Store the CPU program counter in the PCB's program counter. // c. Store the CPU's value in the PCB's value
  • 26. cout << " adding pid = " << pcbTable[runningState]- >processId << " to the block queue" <<endl; pcbTable[runningState]->state = STATE_BLOCKED; pcbTable[runningState]->programCounter = cpu.programCounter; pcbTable[runningState]->value = cpu.value; // 3. Update the running state to -1 (basically mark no process as running). // Note that a new process will be chosen to run later (via the Q command // code calling the schedule() function). runningState = -1; } /**************************************************** ************************************** * Instruction E terminates the currently running simulated process, frees up all memory * (e.g. program array) associated with that process and updates the PcbTable. * A simulated process from the ready state is moved to running state.
  • 27. * This also results in a context switch. ***************************************************** **************************************/ void end() { cout << "running end process " << endl; // TODO:Get the PCB entry of the running process. cumulativeTimeDiff = timestamp + 1 - pcbTable[runningState]->startTime; ++numTerminatedProcesses; runningState = -1; // memory will get freed when the simulation terminates. } /**************************************************** *************************************************** * Instruction F results in the creation of a new simulated process. A new entry is created in * the PcbTable for this new simulated process. A new (unique) process id is assigned and the
  • 28. * parent process id is process id of the parent simulated process. Start time is set to the current * Time value and CPU time used so far is set to 0. The program array and integer value of the new * simulated process are a copy of the program array and integer value of the parent simulated process. * The new simulated process has the same priority as the parent simulated process. * * The program counter value of the new simulated process is set to the instruction immediately * after the F instruction, while the program counter value of the of the parent simulated process * is set to n instructions after the next instruction (instruction immediately after F). * * The new simulated process is created in the ready state. ***************************************************** **************************************************/ void fork(int value) { cout << "running fork process " << endl;
  • 29. PcbEntry *myPCB = new PcbEntry(); myPCB->program = pcbTable[runningState]->program; if ((value > -2) && (value < 1000)){//ensure passed in method not out of bounds try{//catch all out of range myPCB->processId = pcbTable.size();//a PCB index+table.size myPCB->parentProcessId = pcbTable[runningState]->processId; myPCB->programCounter = cpu.programCounter; myPCB->value = cpu.value; myPCB->priority = pcbTable[runningState]- >priority; myPCB->state = STATE_READY;//dont forget to add to ready queue myPCB->startTime = timestamp; pcbTable.push_back(myPCB);//queue push back, pull front readyState.push_back(myPCB->processId); cpu.programCounter = cpu.programCounter + value;
  • 30. cout << " forked process, pid = " << myPCB- >processId << " and pushed it to the ready queue" << endl; } catch (const out_of_range& oor) { std::cerr << "Out of Range error: " << oor.what() << 'n'; } catch(const runtime_error& re) { cout << "Exception caught: " << re.what() << 'n'; } } else cout << "value is out of bounds" << endl; } /**************************************************** ************************************************** * The R instruction results in replacing the process image of the currently
  • 31. * running simulated process. Its program array is overwritten by the code in file filename, * program counter value is set to 0, and integer value is undefined. Note that all these changes * are made only in the Cpu data structure. Process id, parent process id, start time, * CPU time used so far, state, and priority remain unchanged. ***************************************************** ************************************************/ void replace(string &argument) { cout << "running replace process opening file " << endl; cpu.pProgram->clear();//shouldnt I read argument first? cout << "replace argument is " << argument << endl; if (!createProgram(argument, *cpu.pProgram)) {//storing file into pProgram cout << " ERROR can not open file!" << endl; cpu.programCounter = cpu.programCounter + 1; //do more error handling }
  • 32. else { cpu.programCounter = 0; cout << " createprogram..sucess" << endl; } } // Implements the Q command. /**************************************************** ************************************************* * On receiving a Q command, * the process manager executes the next instruction of the currently running simulated process, * increments program counter value (except for F or R instructions), increments Time, * and then performs scheduling. Note that scheduling may involve performing context switching. ***************************************************** ************************************************/ void quantum() {
  • 33. cout << "starting quantum process " << endl; Instruction instruction; if (runningState == -1) { cout << "No processes are running" << endl; ++timestamp; return; } if (cpu.programCounter < cpu.pProgram->size()) { instruction = (*cpu.pProgram)[cpu.programCounter]; cpu.programCounter++; } else { cout << "End of program reached without E operation" << endl; instruction.operation = 'E'; } switch (instruction.operation) { case 'S':
  • 34. set(instruction.intArg); break; case 'A': add(instruction.intArg); break; case 'D': decrement(instruction.intArg); break; case 'B': block(); break; case 'E': end(); break; case 'F': fork(instruction.intArg); break; case 'R':
  • 35. replace(instruction.stringArg); break; } ++timestamp; schedule(); } // Implements the U command. void unblock() { cout << "entered unblocked method" << endl; if(!blockedState.empty()){//check for empty queue int pcbIndex = blockedState.front(); cout << " unblocking PID = " << pcbIndex << " adding it to ready que" << endl; blockedState.pop_front(); readyState.push_back(pcbIndex);
  • 36. pcbTable[pcbIndex]->state = STATE_READY; schedule(); } else {cout << " blocked buffer was empty" << endl; } } /**************************************************** ********************************************* * On receiving a P command, the process manager spawns a new reporter process. ***************************************************** *******************************************/ void print() { cout << "Print command is not implemented until iLab 3" << endl; } // Function that implements the process manager. /****************************************************
  • 37. ********************************************* * The process manager process simulates four process management functions: * 1. creation of new (simulated) processes, * 2. replacing the current process image of a simulated process with a new process image, * 3. management of process state transitions, * 4. process scheduling. ***************************************************** ********************************************/ int runProcessManager(int fileDescriptor) { PcbEntry *pcbEntry = new PcbEntry(); const char *INITPATH = "init"; // Attempt to create the init process. /**************************************************** *************************************************** * The process manager creates[createProgram()] the first simulated process (process id = 0) program from an input file
  • 38. * (filename: init). This is the only simulated process created by the process manager on its own. * All other simulated processes are created in response to the execution of the F instruction * ***************************************************** ************************************************/ if (!createProgram(INITPATH , pcbEntry->program)) { delete pcbEntry; return EXIT_FAILURE; } /**************************************************** **************************************************** * The process manager maintains six data structures: They are in the pcbEntry class * Time, Cpu, PcbTable, {[state::] ReadyState, BlockedState, and RunningState.} ***************************************************** *************************************************/ pcbEntry->processId = pcbTable.size(); pcbEntry->parentProcessId = -1;
  • 39. pcbEntry->programCounter = 0; pcbEntry->value = 0; pcbEntry->priority = 0; pcbEntry->state = STATE_RUNNING; // Time is an integer variable initialized to zero. pcbEntry->startTime = 0; pcbEntry->timeUsed = 0; /**************************************************** ***************************************************** * PcbTable is an array with one entry for every simulated process that hasn't finished its execution yet. * Each entry should include data members to store process id, parent process id, a pointer to program counter * value (initially 0), integer value, priority, state, start time, and CPU time used so far. ***************************************************** ***************************************************/ pcbTable.push_back(pcbEntry);
  • 40. runningState = pcbEntry->processId; cout << "Running init process, pid = " << pcbEntry- >processId << endl; /**************************************************** ***************************************************** * Cpu is used to simulate the execution of a simulated process that is in running state. * It should include data members to store a pointer to the program array, current program counter value, * integer value, and time slice of that simulated process. In addition, it should store the number of * time units used so far in the current time slice. ***************************************************** ****************************************************/ cpu.pProgram = &(pcbEntry->program); cpu.programCounter = pcbEntry->programCounter; cpu.value = pcbEntry->value;
  • 41. timestamp = 0; double avgTurnaroundTime = 0; // Loop until a 'T' is read, then terminate. char ch; do { // Read a command character from the pipe. /************************************************ **************************************************** * After creating the first process and initializing all its data structures, * the process manager repeatedly receives and processes one command at a time * from the commander process (read via the pipe). * ***************************************************** *********************************************/ if (read(fileDescriptor, &ch, sizeof(ch)) != sizeof(ch)) { // Assume the parent process exited, breaking the pipe. break;
  • 42. } // Ignore whitespace characters. if (isspace(ch)) { continue; } // Convert commands to a common case so both lower and uppercase // commands can be used. ch = toupper(ch); switch (ch) { case 'Q': quantum(); break; case 'U': unblock();
  • 43. break; case 'P': print(); break; /**************************************************** ************************************** * On receiving a T command, the process manager first spawns a reporter process and then * terminates after termination of the reporter process. The process manager ensures that * no more than one reporter process is running at any moment. ***************************************************** ************************************/ case 'T': if (numTerminatedProcesses != 0) { avgTurnaroundTime = cumulativeTimeDiff / (double)numTerminatedProcesses; } cout << "The average turnaround time is " <<
  • 44. avgTurnaroundTime << "." << endl; break; default: cout << "Unknown command, " << ch << endl; } } while (ch != 'T'); // Cleanup any remaining PCB entries. for (vector<PcbEntry *>::iterator it = pcbTable.begin(); it != pcbTable.end(); it++) { delete *it; } pcbTable.clear(); return EXIT_SUCCESS; } //recieves a pipe descriptor
  • 45. int main(int argc, char** argv) { //variables} int result; int pfd[2]; //read arguments if(argc < 3) { cout << "You must provide a pipe adress descriptor " << endl; // Keeep command window open until user presses ENTER key cout << "Press ENTER key to exit" << endl; cin.ignore( ); exit(0); } pfd[0] = atoi(argv[2]); // Run the process manager. result = runProcessManager(pfd[0]); // Close the read end of the pipe for the process manager process (for // cleanup purposes).
  • 46. cout << "closing pipe...GOODBYE" << endl; close(pfd[0]);//close read end of pipe //exit (using the _exit() system call). exit(result); // Keeep command window open until user presses ENTER key cout << "Press ENTER key to exit" << endl; cin.ignore( ); return(0); } JGilchrist_lab2 Code.txt /* * File: week1ECET360.cpp * Author: JGilchrist * * Created on November 5, 2013, 8:20 PM */
  • 47. #pragma GCC diagnostic ignored "-Wwrite-strings" //compiler directive? Cplusplus.com #include <cstdlib> // for EXIT_SUCCESS and EXIT_FAILURE #include <iostream> // for cout, endl, and cin #include <stdio.h> #include <sys/wait.h> // for wait() #include <unistd.h> // for pipe(), read(), write(), close(), fork(), and _exit() using namespace std; /*************************************** *Used from the the partial code given ****************************************/ /* Commander Process: */ int main(int argc, char** argv) { int result = 0; int pfd[2];
  • 48. pid_t cpid; //cpid of type integer defined types.h //Via Paul Nichols bool parentLoop = true;//control variable for write loop, break?CPlusplus.con char userInput; //user input if (pipe(pfd) == -1) {//creating the pipe perror("pipe failed"); exit(EXIT_FAILURE); } //fork a child process after the pipe is made so they both have same PFD via http://www.advancedlinuxprogramming.com/alp- folder/alp-ch03-processes.pdf cpid = fork(); if (cpid == -1) {//if fork returned error exit perror("fork failed"); //via Paul Nichols exit(EXIT_FAILURE); } //wait for a second so child doesnt write over parent
  • 49. sleep(1);//linux sleep 1 second if using windows Sleep(milliseconds) if(cpid != 0) { //this is the parent-->Commander process********************************************** *** close(pfd[0]); //closing read end on parent...parent only writes cout << "commands are 'Q', 'U', 'P', or 'T' to quit"<<endl; while(parentLoop == true){ sleep(1);//linux sleep 1 second if using windows Sleep(milliseconds) cout << "enter a command: "; cin >> userInput; cout << endl; // cout for the user input if((userInput=='Q') || (userInput=='U')||(userInput=='P')){ /************************************************ ************************************ * The commander process accepts four commands: Used from the ILab Tab * 1. Q: End of one unit of time.
  • 50. * 2. U: Unblock the first simulated process in blocked queue. * 3. P: Print the current state of the system. * 4. T: Print the average turn around time, and terminate the system. ************************************************ *************************************/ //write info to pipe if(write(pfd[1], &userInput, sizeof(userInput)) < 0) exit(EXIT_FAILURE); //sleep(.5);//linux sleep 1 second if using windows Sleep(milliseconds) } else if(userInput == 'T'){ cout << "user input is T...Terminating parent" << endl; parentLoop = false; if(write(pfd[1], &userInput, 1) < 0){ perror("pipe write failed"); exit(EXIT_FAILURE);
  • 51. } } else { cout << "invalid input, please enter values of 'Q', 'U', 'P', or 'T' to quitn" << endl; } } cout << "waiting for child process to close.."<<endl; close(pfd[1]);//close write end of pipe wait(NULL);// wait for child to close exit(EXIT_SUCCESS); }//end of parent process code************************************************* *************************** else { //this is child--swap--> Process Manager process //execl( project_manager_loc , "Project_Manager", argv[1], &string1[0], (char *) 0); close(pfd[1]);//close write end of pipe
  • 52. char *project_manager_loc = "./Project_Manager"; char string1[12]; // A 32 bit number can't take more than 11 characters, + a terminating 0 snprintf(string1,12,"%i",pfd[0]); // Copy the file descriptor into a string char *args_1[] = {"Project_Manager", argv[0], &string1[0], (char *) 0}; execve( project_manager_loc , args_1, NULL); cout << "Error executing child...can not open" << endl; close(pfd[0]); cout << "exiting" << endl; }//end process _exit(result); } week2.png JGilchrist_Lab3_7.txt #define ENABLE_COMMANDER
  • 53. #define ENABLE_REPORTER #include <cctype> // for toupper() #include <cstdlib> // for EXIT_SUCCESS and EXIT_FAILURE #include <cstring> // for strerror() #include <cerrno> // for errno #include <deque> // for deque (used for ready and blocked queues) #include <fstream> // for ifstream (used for reading simulated process programs) #include <iostream> // for cout, endl, and cin #include <sstream> // for stringstream (for parsing simulated process programs) #include <sys/wait.h> // for wait() #include <unistd.h> // for pipe(), read(), write(), close(), fork(), and _exit() #include <vector> // for vector (used for PCB table) using namespace std;
  • 54. class Instruction { public: char operation; int intArg; string stringArg; }; class Cpu { public: vector<Instruction> *pProgram; int programCounter; int value; int timeSlice; int timeSliceUsed; };
  • 55. enum State { STATE_READY, STATE_RUNNING, STATE_BLOCKED, STATE_END }; class PcbEntry { public: int processId; int parentProcessId; vector<Instruction> program; unsigned int programCounter; int value; unsigned int priority; State state;
  • 56. unsigned int startTime; unsigned int timeUsed; }; // The number of valid priorities. #define NUM_PRIORITIES 4 // An array that maps priorities to their allotted time slices. static const unsigned int PRIORITY_TIME_SLICES[NUM_PRIORITIES] = { 1, 2, 4, 8 };
  • 57. unsigned int timestamp = 0; Cpu cpu; // For the states below, -1 indicates empty (since it is an invalid index). int runningState = -1; // The index of the running process in the PCB table. // readyStates is an array of queues. Each queue holds PCB indices for ready processes // of a particular priority. deque<int> readyStates[NUM_PRIORITIES]; deque<int> blockedState; // A queue fo PCB indices for blocked processes. deque<int> deadState; // In this implementation, we'll never explicitly clear PCB entries and the // index in the table will always be the process ID. These choices waste memory, // but since this program is just a simulation it the easiest
  • 58. approach. // Additionally, debugging is simpler since table slots and process IDs are // never re-used. vector<PcbEntry *> pcbTable; double cumulativeTimeDiff = 0; int numTerminatedProcesses = 0; // Sadly, C++ has no built-in way to trim strings: string &trim(string &argument) { string whitespace(" tnvfr"); size_t found = argument.find_last_not_of(whitespace); if (found != string::npos) { argument.erase(found + 1); argument.erase(0,
  • 59. argument.find_first_not_of(whitespace)); } else { argument.clear(); // all whitespace } return argument; } bool createProgram(const string &filename, vector<Instruction> &program) { ifstream file; int lineNum = 0; program.clear(); file.open(filename.c_str());
  • 60. if (!file.is_open()) { cout << "Error opening file " << filename << endl; return false; } while (file.good()) { string line; getline(file, line); trim(line); if (line.size() > 0) { Instruction instruction; instruction.operation = toupper(line[0]);
  • 61. instruction.stringArg = trim(line.erase(0, 1)); stringstream argStream(instruction.stringArg); switch (instruction.operation) { case 'S': // Integer argument. case 'A': // Integer argument. case 'D': // Integer argument. case 'F': // Integer argument. if (!(argStream >> instruction.intArg)) { cout << filename << ":" << lineNum << " - Invalid integer argument " << instruction.stringArg << " for " << instruction.operation << " operation" << endl; file.close();
  • 62. return false; } break; case 'B': // No argument. case 'E': // No argument. break; case 'R': // String argument. // Note that since the string is trimmed on both ends, // filenames with leading or trailing whitespace (unlikely) // will not work. if (instruction.stringArg.size() == 0) { cout << filename << ":" << lineNum << " - Missing string argument" << endl; file.close(); return false;
  • 63. } break; default: cout << filename << ":" << lineNum << " - Invalid operation, " << instruction.operation << endl; file.close(); return false; } program.push_back(instruction); } lineNum++; }
  • 64. file.close(); return true; } // Implements the S operation. void set(int value) { cpu.value = value; cout << "Set CPU value to " << value << endl; } // Implements the A operation. void add(int value) {
  • 65. cpu.value += value; cout << "Incremented CPU value by " << value << endl; } // Implements the D operation. void decrement(int value) { cpu.value -= value; cout << "Decremented CPU value by " << value << endl; } // Performs scheduling. void schedule() { // TODO: Debug and test //If runningState != -1 AND the cpu.timeSliceUsed equals or
  • 66. exceeds // cpu.timeSlice: cout <<" cpu timeslice Used " << cpu.timeSliceUsed<<endl; cout <<" cpu timeslice " << cpu.timeSlice<<endl; if ((runningState != -1) && (cpu.timeSliceUsed >= cpu.timeSlice)){ // 1. Get the PCB entry for runningState. PcbEntry *myPCB = pcbTable[runningState]; // 2. Lower the process priority (remember since the highest priority is zero, // you actually have to increment the priority to lower it). Also make sure to // not increment the priority past its maximum value. if (myPCB->priority >= 0 && myPCB->priority < (NUM_PRIORITIES - 1)) myPCB->priority++;
  • 67. // 3. Push runningState on to the end of the correct readyStates queue (hint: use // pcbEntry.priority to select the correct queue. switch (myPCB->priority) { case 0 : readyStates[0].push_back(runningState); break; case 1 : readyStates[1].push_back(runningState); break; case 2 : readyStates[2].push_back(runningState); break; case 3 : readyStates[3].push_back(runningState); break;
  • 68. default: cout << "Invalid running state" << endl; break; } // 4. Update the pcbEntry: // a. Set state to STATE_READY. // b. Set the programCounter to cpu.programCounter. // c. Set the value to cpu.value. // d. Increment timeUsed by cpu.timeSliceUsed. myPCB->state = STATE_READY; myPCB->programCounter = cpu.programCounter; myPCB->value = cpu.value; myPCB->timeUsed = myPCB->timeUsed + cpu.timeSliceUsed; cout << " time this process has used = " << myPCB- >timeUsed << endl; cout << " scheduler is ending process and decreasing priority to "<< myPCB->priority <<"n" << endl;
  • 69. // 5. Set runningState to -1. runningState = -1; } if (runningState != -1) {//the correct priority program is running cout << " correct process is running exiting scheduler" << endl; return; } cout << " loading new process from "; // TODO: Debug and test // Get a new process to run, if possible, from the ready queue in // priority order. Remember that the highest priority is zero! The code below // needs to be updated/replaced since right now it only uses the highest priority // queue.
  • 70. if(!readyStates[0].empty()){ runningState = readyStates[0].front(); cout << "priority 0 " << endl; readyStates[0].pop_front(); } else if(!readyStates[1].empty()){ runningState = readyStates[1].front(); cout << "priority 1" << endl; readyStates[1].pop_front(); } else if(!readyStates[2].empty()){ runningState = readyStates[2].front(); cout << "priority 2 " << endl; readyStates[2].pop_front(); } else if(!readyStates[3].empty()){ runningState = readyStates[3].front(); cout << "priority 3 " << endl;
  • 71. readyStates[3].pop_front(); } else cout << "ERROR ready state has invalid state entries"; // Make sure there is a process to run. if (runningState != -1) { // Mark the process as running. PcbEntry *pcbEntry = pcbTable[runningState]; pcbEntry->state = STATE_RUNNING; // Update the CPU with new PCB entry details. cpu.pProgram = &pcbEntry->program; cpu.programCounter = pcbEntry->programCounter; cpu.value = pcbEntry->value;
  • 72. // TODO: Debug and test // Set cpu.timeSlice to the correct value (hint: use the // global PRIORITY_TIME_SLICES array and pcbEntry- >priority) switch (pcbEntry->priority) { case 0 : cpu.timeSlice = PRIORITY_TIME_SLICES[0]; cout << " setting cpu.timeslice to 1"<<endl; break; case 1 : cpu.timeSlice = PRIORITY_TIME_SLICES[1]; cout << " setting cpu.timeslice to 2"<<endl; break; case 2 : cpu.timeSlice =
  • 73. PRIORITY_TIME_SLICES[2]; cout << " setting cpu.timeslice to 4"<<endl; break; case 3 : cpu.timeSlice = PRIORITY_TIME_SLICES[3]; cout << " setting cpu.timeslice to 8"<<endl; break; default: cout << "ERROR setting cpu timeslice Invalid priority" << endl; break; } // TODO: Debug and test // Set cpu->timeSliceUsed to zero. cpu.timeSliceUsed = 0;
  • 74. cout << "Process running, pid = " << pcbEntry->processId << endl; } } // Implements the B operation. void block() { PcbEntry *pcbEntry = pcbTable[runningState]; //TODO there is a problem with pcb time used counter will this fix it pcbEntry->timeUsed += cpu.timeSliceUsed + 1;//add 1 for CPU time to block the process // TODO: Debug and test // Raise the process priority (remember since the highest
  • 75. priority is zero, // you actually have to decrement the priority to raise it). Also make sure to // not decrement the priority below zero. if (pcbEntry->priority > 0) pcbEntry->priority--; blockedState.push_back(runningState); pcbEntry->state = STATE_BLOCKED; pcbEntry->programCounter = cpu.programCounter; pcbEntry->value = cpu.value; runningState = -1; cout << "Blocked process, pid = " << pcbEntry->processId << endl;
  • 76. } // Implements the E operation. void end() { PcbEntry *pcbEntry = pcbTable[runningState]; //TODO there is a problem with pcb timused will this fix it? pcbEntry->timeUsed = pcbEntry->timeUsed + cpu.timeSliceUsed + 1;//add 1 to account for e operation // Add 1 to account for the time to execute the E operation. cumulativeTimeDiff += (double)(timestamp + 1 - pcbEntry- >startTime); numTerminatedProcesses++;
  • 77. cout << "Ended process, pid = " << pcbEntry->processId << endl; pcbEntry->state = STATE_END; deadState.push_back(runningState); runningState = -1; } // Implements the F operation. void fork(int value) { int pcbIndex = (int)pcbTable.size(); PcbEntry *runningPcbEntry = pcbTable[runningState]; PcbEntry *pcbEntry = new PcbEntry(); pcbEntry->processId = pcbIndex;
  • 78. pcbEntry->parentProcessId = runningPcbEntry->processId; pcbEntry->program = runningPcbEntry->program; pcbEntry->programCounter = cpu.programCounter; pcbEntry->value = cpu.value; pcbEntry->priority = runningPcbEntry->priority; pcbEntry->state = STATE_READY; pcbEntry->startTime = timestamp + 1; pcbEntry->timeUsed = 0; pcbTable.push_back(pcbEntry); // TODO: debug and test //Update the line below to use the correct readyStates queue. readyStates[pcbEntry->priority].push_back(pcbIndex); cout << "Forked new process, pid = " << pcbEntry-
  • 79. >processId << endl; if ((value < 0) || (cpu.programCounter + value >= (int)cpu.pProgram- >size())) { cout << "Error executing F operation, ending parent process" << endl; end(); } cpu.programCounter += value; } // Implements the R operation. void replace(string &argument) {
  • 80. if (!createProgram(argument, *cpu.pProgram)) { cout << "Error executing R operation, ending process" << endl; end(); return; } cpu.programCounter = 0; cout << "Replaced process with " << argument << ", pid = " << pcbTable[runningState]->processId << endl; } // Implements the Q command. void quantum() { Instruction instruction; if (runningState == -1) {
  • 81. cout << "No processes are running" << endl; ++timestamp; return; } if (cpu.programCounter < (int)cpu.pProgram->size()) { instruction = (*cpu.pProgram)[cpu.programCounter]; cpu.programCounter++; } else { cout << "End of program reached without E operation" << endl; instruction.operation = 'E'; } switch (instruction.operation) { case 'S': set(instruction.intArg);
  • 82. break; case 'A': add(instruction.intArg); break; case 'D': decrement(instruction.intArg); break; case 'B': block(); break; case 'E': end(); break; case 'F': fork(instruction.intArg); break; case 'R': replace(instruction.stringArg);
  • 83. break; } timestamp++; // TODO: degug and test // Increment cpu.timeSliceUsed. cpu.timeSliceUsed++; schedule(); } // Implements the U command. void unblock() { if (!blockedState.empty()) { int pcbIndex = blockedState.front(); PcbEntry *pcbEntry = pcbTable[pcbIndex]; blockedState.pop_front(); // TODO: debug and test. PHIL << "this process does not increment the timeStamp, because it comes from Commander?"
  • 84. // Update the line below to use the correct readyStates queue. readyStates[pcbEntry->priority].push_back(pcbIndex); pcbEntry->state = STATE_READY; cout << "Unblocked process, pid = " << pcbEntry- >processId << endl; } schedule(); } void printReadyQue(int *myArray){ for (unsigned int j = 0; j < NUM_PRIORITIES; j++){ if (!readyStates[j].empty()){
  • 85. cout << "READY STATE PRIORITY " << j << " QUEUE:n pid | ppid | priority | value | start time | cpu time used |" << endl; for (unsigned int i = 0; i < readyStates[j].size(); i++) { int pcbIndex = readyStates[j][i]; PcbEntry *pcbEntry = pcbTable[pcbIndex]; printf("% *d % *d % *d % *d % *d % *d n" , 7 , pcbEntry->processId , 11, pcbEntry->parentProcessId, 10, pcbEntry->priority, 10, pcbEntry->value, 10, pcbEntry->startTime, 10, pcbEntry->timeUsed); myArray[j] = myArray[j]+1;//increment prioriety myArray[4] += pcbEntry->timeUsed;//sum } } } }
  • 86. void printProcess(int *myArray){ int myTimeUsed = 0; const int NUM_STATE = 4; State myState[NUM_STATE] = {STATE_READY , STATE_RUNNING, STATE_BLOCKED, STATE_END}; for (int j =1; j < NUM_STATE; j++){ switch (j) { case 1: cout << "RUNNING PROCESSSES:n pid | ppid | priority | value | start time | cpu time used |" << endl; break; case 2: if (!blockedState.empty()) cout << "BLOCKED PROCESSSES:n pid | ppid | priority | value | start time | cpu time used |" << endl; break; case 3: if (!deadState.empty()) cout << "DEAD PROCESSSES:n pid | ppid | priority | value | start time | cpu time used |" << endl;
  • 87. break; default: cout << "ERROR!!!!!"; break; } for(unsigned int readyEntry = 0; readyEntry < pcbTable.size(); readyEntry++){ if (pcbTable[readyEntry]->state == myState[j] ){ if (pcbTable[readyEntry]->state == STATE_RUNNING)myTimeUsed = pcbTable[runningState]- >timeUsed+cpu.timeSliceUsed; else myTimeUsed = pcbTable[readyEntry]- >timeUsed; printf("% *d % *d % *d % *d % *d % *d n" , 7 , pcbTable[readyEntry]->processId , 11, pcbTable[readyEntry]->parentProcessId, 10, pcbTable[readyEntry]->priority, 10, pcbTable[readyEntry]- >value, 10, pcbTable[readyEntry]->startTime, 10, myTimeUsed);
  • 88. myArray[pcbTable[readyEntry]- >priority]++;//increment prioriety myArray[4] += myTimeUsed; } } } } void printPriorieties(int *prioritieList){ cout << endl; for (int i =0; i<4; i++){ if ( prioritieList[i] != 0) cout << "number of processes with priority "<< i << " is: " << prioritieList[i] << endl; } if ((int)timestamp == prioritieList[4]) cout << "nCURRENT TIME: " << timestamp << " = " << "total CPU TIME USED: "<< prioritieList[4] << endl; else cout << "PCB total time does not match this can only happen if no process was running" << endl;
  • 89. } // Implements the P command. void print() { #ifdef ENABLE_REPORTER pid_t pid; pid = fork(); if (pid == -1) { cout << "fork:" << strerror(errno) << endl; return; } if (pid != 0) { // Wait for the reporter process to exit.
  • 90. wait(NULL); return; } #endif #ifdef ENABLE_REPORTER // TODO: debug and test //Implement all of the printing logic. int prioritieList[NUM_PRIORITIES + 1] = {0,0,0,0,0};//+ one for sum[4] counter cout << "n---------------------------------------------------------- ------------" << endl; //cout << "CURRENT TIME: " << timestamp<< endl; printReadyQue(prioritieList);//prints the processes in ready state by que printProcess(prioritieList);// prints the rest of the processes printPriorieties(prioritieList); cout << "------------------------------------------------------------- ---------n"<<endl; _exit(EXIT_SUCCESS);
  • 91. #endif } // Function that implements the process manager. int runProcessManager(int fileDescriptor) { PcbEntry *pcbEntry = new PcbEntry(); // Attempt to create the init process. if (!createProgram("Users/JGilchrist/Desktop/ECET365/week1/" , pcbEntry->program)) { delete pcbEntry; return EXIT_FAILURE; }
  • 92. pcbEntry->processId = (int)pcbTable.size(); pcbEntry->parentProcessId = -1; pcbEntry->programCounter = 0; pcbEntry->value = 0; pcbEntry->priority = 0; pcbEntry->state = STATE_RUNNING; pcbEntry->startTime = 0; pcbEntry->timeUsed = 0; pcbTable.push_back(pcbEntry); runningState = pcbEntry->processId; cout << "Running init process, pid = " << pcbEntry- >processId << endl;
  • 93. cpu.pProgram = &(pcbEntry->program); cpu.programCounter = pcbEntry->programCounter; cpu.value = pcbEntry->value; timestamp = 0; double avgTurnaroundTime = 0; // Loop until a 'T' is read, then terminate. char ch; do { // Read a command character from the pipe. if (read(fileDescriptor, &ch, sizeof(ch)) != sizeof(ch)) { // Assume the parent process exited, breaking the pipe.
  • 94. break; } // Ignore whitespace characters. if (isspace(ch)) { continue; } // Convert commands to a common case so both lower and uppercase // commands can be used. ch = toupper(ch);
  • 95. switch (ch) { case 'Q': quantum(); break; case 'U': unblock(); break; case 'P': print(); break; case 'T': if (numTerminatedProcesses != 0) { avgTurnaroundTime = cumulativeTimeDiff / (double)numTerminatedProcesses; } cout << "The average turnaround time is " << avgTurnaroundTime << "." << endl; break;
  • 96. default: cout << "Unknown command, " << ch << endl; break; } } while (ch != 'T'); // Cleanup any remaining PCB entries. for (vector<PcbEntry *>::iterator it = pcbTable.begin(); it != pcbTable.end(); it++) { delete *it; } pcbTable.clear(); return EXIT_SUCCESS; }
  • 97. // Main function that implements the commander. int main(int argc, char *argv[]) { #ifdef ENABLE_COMMANDER int pipeDescriptors[2]; pid_t processMgrPid; char ch; int result; // Create a pipe. if (pipe(pipeDescriptors) == -1) { // Print an error message to help debugging. cout << "pipe: " << strerror(errno) << endl; return EXIT_FAILURE; }
  • 98. // Create the process manager process. processMgrPid = fork(); if (processMgrPid == -1) { // Print an error message to help debugging. cout << "fork: " << strerror(errno) << endl; return EXIT_FAILURE; } if (processMgrPid == 0) { // The process manager process is running. // Close the unused write end of the pipe for the process manager // process. close(pipeDescriptors[1]);
  • 99. // Run the process manager. result = runProcessManager(pipeDescriptors[0]); // Close the read end of the pipe for the process manager process (for // cleanup purposes). close(pipeDescriptors[0]); _exit(result); } else { // The commander process is running. // Close the unused read end of the pipe for the commander process. close(pipeDescriptors[0]);
  • 100. // Loop until a 'T' is written or until the pipe is broken. do { sleep(1); cout << "Input a command: "; // Read a command character from the standard input. cin >> ch; cout << endl; // Pass commands to the process manager process via the pipe. if (write(pipeDescriptors[1], &ch, sizeof(ch)) != sizeof(ch)) { // Assume the child process exited, breaking the pipe. break; } } while (ch != 'T');
  • 101. // Wait for the process manager to exit. wait(&result); // Close the write end of the pipe for the commander process (for // cleanup purposes). close(pipeDescriptors[1]); } return result; #else // Run the Process Manager directly. return runProcessManager(fileno(stdin)); #endif }
  • 102. lab3_7.png Lab-7 Explanation 1- An Install and README file: A single file that gives a brief description of the program, how to install it, how to execute it (you don't really need to explain commands etc., just how to start the program), and maybe references to any other relevant information (i.e. for more information consult the user guide). The overall guidance here is keeping it short and to the point. This is pretty much what most have you have already been providing to me. 2- A User Guide: You need to describe the program's behavior (what the user should expect to see), what the commands are and their purposes. You probably want to describe the format of the "program" files that the simulator runs. Almost all the information you need is on the iLab page itself, except you should describe anything about your program that may be special, different, or not immediately obvious to a user. The overall guidance here is to accurately describe how to use all aspects of the program without talking about how the program works or is implemented (unless it is absolutely essential to understand how to use the program). 3- A System Programming Guide: This guide will explain the design and structure of the program itself. Describe how it works on an internal level. This is a guide a programmer might use, so you want to consider the use cases that relate to a programmer. What if a programmer wanted to add a new command? How about a new program operation? The information contained within should give a programmer a good idea of which parts of the program provide specific functionality, and how that functionality is implemented. You
  • 103. don't want to go down to the level of describing the code itself in words, but you do want to describe any important algorithms in detail, and at least generalize how things work. The overall guidance here is to leave out details about how to run or use the program, and just talk about how the program actually does its job. 4- Manual pages: This is mostly going to be a reformatting of the Users Guide. You should follow the format of a typical Unix/Linux man page (Google around to find some examples). I would include most or all of the things in the User’s Guide.