Question: Sample output Batch scheduling ---------------- 1) Enter parameters 2) Schedule processes with FIFO algorithm 3) Schedule processes with SJF algorithm 4) Schedule processes with SRT

Sample output 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 ID Arrival Total Start End Turnaround -------------------------------------------------- 1 0 6 2 1 3 3 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 ID Arrival Total Start End Turnaround -------------------------------------------------- 1 0 6 0 6 6 2 1 3 6 9 8 3 3 2 9 11 8 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 ID Arrival Total Start End Turnaround -------------------------------------------------- 1 0 6 0 6 6 2 1 3 8 11 10 3 3 2 6 8 5
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 ID Arrival Total Start End Turnaround -------------------------------------------------- 1 0 6 0 11 11 2 1 3 1 4 3 3 3 2 4 6 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: 5
Quitting program......
// Code
#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;
/***************************************************************/ 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) */
} return; } /***************************************************************/ void procedure_1() { /*"PROCEDURE FOR OPTION #1" /* declare local variables */ /* prompt for total number of processes */ /* allocate memory for table to hold process parameters */ /* for each process */ /* prompt for process id, arrival time, and total cycle time */ /* print contents of 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 */
return; }
/***************************************************************/ 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 */
return; }
/***************************************************************/ 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 */
return; } /***************************************************************/ void procedure_5() { /* free the schedule table if not NULL */
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 1; }
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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
