Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is the code: I can't get it to work. I need a function that finds the maximum of two integers. #include #include #include /*

image text in transcribedimage text in transcribedimage text in transcribed

Here is the code: I can't get it to work. I need a function that finds the maximum of two integers.

#include #include #include

/* declare global variables including a table structure to hold scheduling information */ /* optional: define a function that finds the maximum of two integers */ int total_processes = 0;

struct node{ int id; int arrival; int total_cycles; int total_remaining; int done; int start; int already_started; int end; int turnaround; }* table = NULL;

typedef struct node table_type;

/***************************************************************/ void print_table() { /* 1.declare local variables 2. print table header 3. for each process 4. print the contents (id, arrival time, total_cycles) of each field of the table's index 5. if process has been scheduled ("done" field is 1, 6. print other contents (start time, end time, turnaround time) */ printf("ID/tArrival/tTotal/tStart/tEnd/tTurnaround"); printf("-------------------------------------------- "); int i; for(i=0; i

printf("Enter total number of processes: "); scanf("%d", &table[i].arrival);

table = (table_type *)malloc(total_processes * sizeof(table_type)); for(i = 0; i

printf("Enter arrival cycle for process P[%d]: ", i); scanf("%d", &table[i].total_cycles);

/* table[i].id = i; table[i].arrival = -1; table[i].total_cycles = -1; table[i].start = -1; table[i].end = -1; table[i].turnaround = -1; */ print_table(); return; } /***************************************************************/ void procedure_2() { /* "PROCEDURE FOR OPTION #2" /* declare (and initilize when appropriate) local variables */ /* for each process, reset "done" field to 0 */ /* while there are still processes to schedule */ /* initilize the earliest arrival time to INT_MAX (largest integer value) */ /* for each process not yet scheduled */ /* check if process has earlier arrival time than current earliest and update */ /* set start time, end time, turnaround time, done fields for unscheduled process with earliest arrival time */ /* update current cycle time and increment number of processes scheduled */ /* print contents of table */

int i; int done; int min_value; int current_cycle = 0; int max; int min_index;

table[i].done = 0;

while(done

/***************************************************************/ void procedure_3() { /* "PROCEDURE FOR OPTION #3" /* declare (and initilize when appropriate) local variables */ /* for each process, reset "done" field to 0 */ /* while there are still processes to schedule */ /* initilize the lowest total cycle time to INT_MAX (largest integer value) */ /* for each process not yet scheduled */ /* check if process has lower total cycle time than current lowest and has arrival time less than current cycle time and update */ /* set start time, end time, turnaround time, done fields for unscheduled process with lowest (and available) total cycle time */ /* update current cycle time and increment number of processes scheduled */ /* print contents of table */ int done = 0; int min_value; int current_cycle = 0; int min_index; int i; table[i].done = 0; while(done

/***************************************************************/ void procedure_4 () { /* "PROCEDURE FOR OPTION #4" /* declare (and initilize when appropriate) local variables */ /* for each process, reset "done", "total_remaining" and "already_started" fields to 0 */ /* while there are still processes to schedule */ /* initilize the lowest total remaining time to INT_MAX (largest integer value) */ /* for each process not yet scheduled */ /* check if process has lower total remaining time than current lowest and has arrival time less than current cycle time and update */ /* check if process already partially-scheduled */ /* if so, set "start time", "already_started" fields of process with lowest (and available) total remaining cycle time */ /* set end time, turnaround time of process with lowest (and available) total remaining cycle time */ /* decrement total remaining time of process with lowest (and available) total remaining cycle time */ /* if remaining time is 0, set done field to 1, increment cycle time and number of scheduled processes*/ /* print contents of table */ int i; int done = 0; int min_value; int min_index; int current_cycle = 0;

table[i].done = 0; table[i].total_remaining = 0; table[i].already_started = 0;

while(done

} } if(table[min_index].already_started == 0){ table[min_index].start = 1; table[min_index].start = 1; table[min_index].end = current_cycle + 1; table[min_index].turnaround = 1; table[min_index].already_started = 1; } else{ table[min_index].end = current_cycle + 1; table[min_index].turnaround = 1; } table[i].total_remaining = 1; if(total_remaining == 0 && done == 1 ){ table[min_index].done = 1; done++; } current_cycle++; print_table(); return; } /***************************************************************/ void procedure_5() { /* free the schedule table if not NULL */ if(table != NULL){ free(table); }

return; } /***************************************************************/ int main() { /* declare local vars */ /* while user has not chosen to quit */ /* print menu of options */ /* prompt for menu selection */ /* call appropriate procedure based on choice--use switch statement or series of if, else if, else statements */ int choice;

while(choice != 5){

printf("Batching Scheduling "); printf("-------------------------- "); printf("1) Enter parameters "); printf("2) Schedule processses with FIFO algorithm "); printf("3) Schedule processes with SJF algorithm "); printf("4) Schdule processes with SRT algorithm "); printf("5) Quit and free memory ");

printf(" "); printf("Enter selection: "); scanf("%d", &choice); printf(" "); switch(choice){ case 1: procedure_1(); break; case 2: procedure_2(); break; case 3: procedure_3(); break; case 4: procedure_4(); break; case 5: procedure_5(); break; } } return 0; }

COMP 322/L-Introduction to Operating Systems and System Architecture Assignment \#2-Batch Process Scheduling Objective: To calculate the timing parameters of batch processes based on different scheduling algorithms. Specification: The program mimics the execution of different processes under different scheduling algorithms. The simulation maintains a table that reflects the current state of the system, based on choosing from a menu of choices, where each choice calls the appropriate procedure, where the choices are: 1) Enter parameters 2) Schedule processes with FIFO algorithm 3) Schedule processes with SJF algorithm (non-preemptive) 4) Schedule processes with SRT algorithm (preemptive version of SJF) 5) Quit program and free memory Assignment: - Create a table to record the status of different processes based on the following parameters: id: the unique identifier of the process - arrival: the point in time when the process enters the ready list to be executed by the CPU - total_cpu: the amount of CPU time the process will consume between arrival and departure - total_remaining: the amount of CPU time remaining for a process to complete \{used for SRT scheduling only - done: a flag that indicates whether the process has been successfully completed (1) or not (0) - start time: the time when the process has begun being executed by the CPU - already_started: a flag that indicated whether the process has already begun (1) or not (0) \{used for SRT scheduling only\} - end_time: the time when the process has been completed by the CPU - turnaround_time: the sum of the total CPU time and the waiting time (alternatively: the difference between the end time and the arrival time) - Calculate the values for the start_time, end_time, and turnaround_time for each process based on the selected scheduling algorithm. Batch scheduling 1) Enter parameters 2) Schedule processes with FIFO algorithm 3) Schedule processes with SJF algorithm 4) Schedule processes with SRT algorithm 5) Quit and free memory Enter selection: 1 Enter total number of processes: 3 Enter process id: 1 Enter arrival cycle for process P[1]:0 Enter total cycles for process P[1]:6 Enter process id: 2 Enter arrival cycle for process P[2]:1 Enter total cycles for process P[2] : 3 Enter process id: 3 Enter arrival cycle for process P[3]:3 Enter total cycles for process P[3] : 2 Batch scheduling 1) Enter parameters 2) Schedule processes with FIFO algorithm 3) Schedule processes with SJF algorithm 4) Schedule processes with SRT algorithm 5) Quit and free memory Enter selection: 2 Batch scheduling 1) Enter parameters 2) Schedule processes with FIFO algorithm 3) Schedule processes with SJF algorithm 4) Schedule processes with SRT algorithm 5) Quit and free memory Enter selection: 3 Batch scheduling 1) Enter parameters 2) Schedule processes with FIFO algorithm 3) Schedule processes with SJF algorithm 4) Schedule processes with SRT algorithm 5) Quit and free memory Enter selection: 4 Batch scheduling 1) Enter parameters 2) Schedule processes with FIFO algorithm 3) Schedule processes with SJF algorithm 4) Schedule processes with SRT algorithm 5) Quit and free memory Enter selection: 5 Quitting program

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

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

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago