Modify the following * printer function * inputs - none * return - none * * XXX
ID: 3566552 • Letter: M
Question
Modify the following
* printer function
* inputs - none
* return - none
*
* XXX (describe what it does)
* XXX (include an overview of how shared memory and semaphores are impacted)
*/
void printer()
{
int memory_to_print;
int current_print_job;
int more_print_jobs;
current_print_job = 0;
more_print_jobs = 2;
while (more_print_jobs)
{
if (current_print_job == 0)
{
/* XXX (describe semaphore changes & interactions) */
P(my_semid, OK_TO_PRINT0);
if (print_job[current_print_job] == -1) // XXX (complete) print job is ____
{
more_print_jobs = more_print_jobs - 1;
V(my_semid, OK_TO_SET_OUTPUT0);
}
else // print job is ready or active
{
memory_to_print = 20;
// XXX (sumarize what this call does)
print_memory(current_print_job, memory_to_print);
print_job[current_print_job] = 0; // XXX (complete) print job is ____
/* XXX (describe semaphore changes & interactions) */
V(my_semid, OK_TO_SET_OUTPUT0);
}
}
else // current_print_job == 1
{
/* job 1 operates same as job 0 above, with the following exceptions:
/* XXX (identify primary differences) */
P(my_semid, OK_TO_PRINT1);
if (print_job[current_print_job] == -1) // XXX (complete) print job is ____
{
more_print_jobs = more_print_jobs - 1;
V(my_semid, OK_TO_SET_OUTPUT1);
}
else // print job is ready or active
{
memory_to_print = 30;
print_memory(current_print_job, memory_to_print);
print_job[current_print_job] = 0; // XXX (complete) print job is ____
V(my_semid, OK_TO_SET_OUTPUT1);
}
}
current_print_job = (current_print_job + 1) % 2; // toggle job number
} // end loop
} /* end of printer */
/*******************************************************************************
* print_memory function
* inputs
* current_print_job - job used as index for output/print PCB
* memory_to_print - location in shared memory of block containing
* a set of completed calculation operations ready to print.
* return - none
*
* XXX (briefly describe what this function does)
*/
void print_memory( current_print_job, memory_to_print)
int current_print_job, memory_to_print;
{
int i;
printf("output for current job %d ", current_print_job);
// XXX (describe which PCB is used for looping and why)
for ( i =1; i <= pcbs[current_print_job + 2].num_instructions; i++)
{
// XXX (describe which shared memory block is used and why)
// XXX (identify what the output device this will be printed to is)
printf("%c %d %d %d ", memory[memory_to_print].operation,
memory[memory_to_print].operand1,
memory[memory_to_print].operand2,
memory[memory_to_print].result );
memory_to_print = memory_to_print + 1;
}
printf(" ");
}
1) Provide the user with a simple menu option of printing the output to the screen or a file but not both. See user interface example below:
$ calc2.out F or f Print the output to the file calc.rpt S or s Print the output to the screen
SELECT WHICH OPTION TO EXECUTE 'F' or 'S' and PRESS ENTER
2) Print the output to the selected destination i.e. add support to output to a file named calc.rpt.
3) Add the modulus operator
Explanation / Answer
2)
ODS-destination
specifies to which ODS destination's selection list to write, where ODS-destination can be any valid ODS destination except for the OUTPUT destination.
Default:If you omit ODS-destination, ODS writes to the overall selection list.
Restriction:You cannot write to the OUTPUT destination's selection list.
Tip:To set the selection list for the Output destination to something other than the default.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.