SlideShare a Scribd company logo
1 of 8
Download to read offline
Here is the code: I can't get it to work. I need a function that finds the maximum of two integers.
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
/* 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/n");
printf("--------------------------------------------n");
int i;
for(i=0; i < total_processes; i++){
printf("%dt", table[i].id);
printf("%dt", table[i].arrival);
printf("%dt", table[i].total_cycles);
printf("%dt", table[i].start);
printf("%dt", table[i].end);
printf("%dt", table[i].turnaround);
}
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 */
int 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 < total_processes; i++){
int arrival = -1;
int total_cycles = -1;
printf("Enter process id: ");
scanf("%d", &table[i].id);
}
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 < 1){
min_value = INT_MAX;
if(table[i].done){
if(table[i].arrival < min_value){
min_value = 0;
min_index = 0;
}
} /*for loop*/
table[min_index].start = max(current_cycle, table[min_index].arrival);
table[min_index].end = table[min_index].start + table[min_index].total_cycles;
table[min_index].turnaround = table[min_index].end - table[min_index].total_cycles;
table[min_index].done = 1;
current_cycle = table[min_index].end;
done++;
}
print_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 */
int done = 0;
int min_value;
int current_cycle = 0;
int min_index;
int i;
table[i].done = 0;
while(done < 1){
min_value = INT_MAX;
if(table[i].done == 0){
if((table[i].arrival < min_value) && (table[i].arrival <= current_cycle)){
min_value = 0;
min_index = 0;
}
}
table[min_index].start = 0;
table[min_index].end = 0;
table[min_index].turnaround = 0;
table[min_index].done = 0;
}
done++;
print_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 */
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 < 1){
min_value = INT_MAX;
if(table[i].done){
if((table[i].total_remaining < min_value) && (table[i].arrival <= current_cycle)){
min_value = 0;
min_index = 0;
}
}
}
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 Schedulingn");
printf("--------------------------n");
printf("1) Enter parametersn");
printf("2) Schedule processses with FIFO algorithmn");
printf("3) Schedule processes with SJF algorithmn");
printf("4) Schdule processes with SRT algorithmn");
printf("5) Quit and free memoryn");
printf("n");
printf("Enter selection: ");
scanf("%d", &choice);
printf("n");
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...

More Related Content

Similar to Here is the code- I can't get it to work- I need a function that finds.pdf

#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx
#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx
#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx
katherncarlyle
 
assign4assign4_part1bonnie.c This is a file system ben.docx
assign4assign4_part1bonnie.c  This is a file system ben.docxassign4assign4_part1bonnie.c  This is a file system ben.docx
assign4assign4_part1bonnie.c This is a file system ben.docx
festockton
 
operating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfoperating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdf
aptcomputerzone
 
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdfoperating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
aquazac
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
ARCHANASTOREKOTA
 
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docxC346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
humphrieskalyn
 
Router Queue Simulation in C++ in MMNN and MM1 conditions
Router Queue Simulation in C++ in MMNN and MM1 conditionsRouter Queue Simulation in C++ in MMNN and MM1 conditions
Router Queue Simulation in C++ in MMNN and MM1 conditions
Morteza Mahdilar
 
I need to find run time analysis and description of the algo.pdf
I need to find run time analysis and description of the algo.pdfI need to find run time analysis and description of the algo.pdf
I need to find run time analysis and description of the algo.pdf
aakashenterprises
 
Lab 2 Histrogram generation Author Naga Kandasamy .docx
 Lab 2 Histrogram generation   Author Naga Kandasamy  .docx Lab 2 Histrogram generation   Author Naga Kandasamy  .docx
Lab 2 Histrogram generation Author Naga Kandasamy .docx
aryan532920
 
prog-05.pdfProgramming Assignment #5CSci 430, Spring 2.docx
prog-05.pdfProgramming Assignment #5CSci 430, Spring 2.docxprog-05.pdfProgramming Assignment #5CSci 430, Spring 2.docx
prog-05.pdfProgramming Assignment #5CSci 430, Spring 2.docx
stilliegeorgiana
 
#include iostream #includeData.h #includePerson.h#in.pdf
#include iostream #includeData.h #includePerson.h#in.pdf#include iostream #includeData.h #includePerson.h#in.pdf
#include iostream #includeData.h #includePerson.h#in.pdf
annucommunication1
 
Timers in Unix/Linux
Timers in Unix/LinuxTimers in Unix/Linux
Timers in Unix/Linux
geeksrik
 
Lab Assignment 4 CSE330 Spring 2014 Skeleton Code for ex.docx
 Lab Assignment 4 CSE330 Spring 2014  Skeleton Code for ex.docx Lab Assignment 4 CSE330 Spring 2014  Skeleton Code for ex.docx
Lab Assignment 4 CSE330 Spring 2014 Skeleton Code for ex.docx
MARRY7
 

Similar to Here is the code- I can't get it to work- I need a function that finds.pdf (20)

#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx
#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx
#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx
 
assign4assign4_part1bonnie.c This is a file system ben.docx
assign4assign4_part1bonnie.c  This is a file system ben.docxassign4assign4_part1bonnie.c  This is a file system ben.docx
assign4assign4_part1bonnie.c This is a file system ben.docx
 
operating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfoperating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdf
 
C# labprograms
C# labprogramsC# labprograms
C# labprograms
 
How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012
 
Algo>Queues
Algo>QueuesAlgo>Queues
Algo>Queues
 
2##"+onkeypress="prompt(23)"+##1
2##"+onkeypress="prompt(23)"+##12##"+onkeypress="prompt(23)"+##1
2##"+onkeypress="prompt(23)"+##1
 
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdfoperating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
 
proxyc CSAPP Web proxy NAME IMPORTANT Giv.pdf
  proxyc  CSAPP Web proxy   NAME    IMPORTANT Giv.pdf  proxyc  CSAPP Web proxy   NAME    IMPORTANT Giv.pdf
proxyc CSAPP Web proxy NAME IMPORTANT Giv.pdf
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
 
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docxC346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
 
Router Queue Simulation in C++ in MMNN and MM1 conditions
Router Queue Simulation in C++ in MMNN and MM1 conditionsRouter Queue Simulation in C++ in MMNN and MM1 conditions
Router Queue Simulation in C++ in MMNN and MM1 conditions
 
I need to find run time analysis and description of the algo.pdf
I need to find run time analysis and description of the algo.pdfI need to find run time analysis and description of the algo.pdf
I need to find run time analysis and description of the algo.pdf
 
Qprgs
QprgsQprgs
Qprgs
 
Lab 2 Histrogram generation Author Naga Kandasamy .docx
 Lab 2 Histrogram generation   Author Naga Kandasamy  .docx Lab 2 Histrogram generation   Author Naga Kandasamy  .docx
Lab 2 Histrogram generation Author Naga Kandasamy .docx
 
prog-05.pdfProgramming Assignment #5CSci 430, Spring 2.docx
prog-05.pdfProgramming Assignment #5CSci 430, Spring 2.docxprog-05.pdfProgramming Assignment #5CSci 430, Spring 2.docx
prog-05.pdfProgramming Assignment #5CSci 430, Spring 2.docx
 
Ch10 Program Organization
Ch10 Program OrganizationCh10 Program Organization
Ch10 Program Organization
 
#include iostream #includeData.h #includePerson.h#in.pdf
#include iostream #includeData.h #includePerson.h#in.pdf#include iostream #includeData.h #includePerson.h#in.pdf
#include iostream #includeData.h #includePerson.h#in.pdf
 
Timers in Unix/Linux
Timers in Unix/LinuxTimers in Unix/Linux
Timers in Unix/Linux
 
Lab Assignment 4 CSE330 Spring 2014 Skeleton Code for ex.docx
 Lab Assignment 4 CSE330 Spring 2014  Skeleton Code for ex.docx Lab Assignment 4 CSE330 Spring 2014  Skeleton Code for ex.docx
Lab Assignment 4 CSE330 Spring 2014 Skeleton Code for ex.docx
 

More from doshirajesh75

Hi- I need help with these two questions The flat periwinkle is a sma.pdf
Hi- I need help with these two questions  The flat periwinkle is a sma.pdfHi- I need help with these two questions  The flat periwinkle is a sma.pdf
Hi- I need help with these two questions The flat periwinkle is a sma.pdf
doshirajesh75
 
High lactate threshold High type II fiber percentage High VO2 max High.pdf
High lactate threshold High type II fiber percentage High VO2 max High.pdfHigh lactate threshold High type II fiber percentage High VO2 max High.pdf
High lactate threshold High type II fiber percentage High VO2 max High.pdf
doshirajesh75
 

More from doshirajesh75 (20)

HISTORY- Mr- Alcot is a 68 year old man who developed a harsh- product.pdf
HISTORY- Mr- Alcot is a 68 year old man who developed a harsh- product.pdfHISTORY- Mr- Alcot is a 68 year old man who developed a harsh- product.pdf
HISTORY- Mr- Alcot is a 68 year old man who developed a harsh- product.pdf
 
Histology- Identify the following 3 slides and the parts indicated- a-.pdf
Histology- Identify the following 3 slides and the parts indicated- a-.pdfHistology- Identify the following 3 slides and the parts indicated- a-.pdf
Histology- Identify the following 3 slides and the parts indicated- a-.pdf
 
Hi- I need help with these two questions The flat periwinkle is a sma.pdf
Hi- I need help with these two questions  The flat periwinkle is a sma.pdfHi- I need help with these two questions  The flat periwinkle is a sma.pdf
Hi- I need help with these two questions The flat periwinkle is a sma.pdf
 
High lactate threshold High type II fiber percentage High VO2 max High.pdf
High lactate threshold High type II fiber percentage High VO2 max High.pdfHigh lactate threshold High type II fiber percentage High VO2 max High.pdf
High lactate threshold High type II fiber percentage High VO2 max High.pdf
 
Here are simplified financial statements for Phone Corporation in a re (1).pdf
Here are simplified financial statements for Phone Corporation in a re (1).pdfHere are simplified financial statements for Phone Corporation in a re (1).pdf
Here are simplified financial statements for Phone Corporation in a re (1).pdf
 
HIPPARCOS (an acronym for HIgh Precision PARallax COllecting Satellite (1).pdf
HIPPARCOS (an acronym for HIgh Precision PARallax COllecting Satellite (1).pdfHIPPARCOS (an acronym for HIgh Precision PARallax COllecting Satellite (1).pdf
HIPPARCOS (an acronym for HIgh Precision PARallax COllecting Satellite (1).pdf
 
Hippocampal LTP-induced increases in transcription- Are primarily the.pdf
Hippocampal LTP-induced increases in transcription- Are primarily the.pdfHippocampal LTP-induced increases in transcription- Are primarily the.pdf
Hippocampal LTP-induced increases in transcription- Are primarily the.pdf
 
Suppose an individuifhas a utiity function given by U(W)- en0-5w where.pdf
Suppose an individuifhas a utiity function given by U(W)- en0-5w where.pdfSuppose an individuifhas a utiity function given by U(W)- en0-5w where.pdf
Suppose an individuifhas a utiity function given by U(W)- en0-5w where.pdf
 
Suppose an XX individual and an XY individual are trying to conceive a.pdf
Suppose an XX individual and an XY individual are trying to conceive a.pdfSuppose an XX individual and an XY individual are trying to conceive a.pdf
Suppose an XX individual and an XY individual are trying to conceive a.pdf
 
Suppose an attacker has managed to gain access and a means of distribu.pdf
Suppose an attacker has managed to gain access and a means of distribu.pdfSuppose an attacker has managed to gain access and a means of distribu.pdf
Suppose an attacker has managed to gain access and a means of distribu.pdf
 
Suppose an individual has a utility function given by U(W) - e^0-5w wh.pdf
Suppose an individual has a utility function given by U(W) - e^0-5w wh.pdfSuppose an individual has a utility function given by U(W) - e^0-5w wh.pdf
Suppose an individual has a utility function given by U(W) - e^0-5w wh.pdf
 
Suppose Alice wants to send a message to Bob containing her name (N) a.pdf
Suppose Alice wants to send a message to Bob containing her name (N) a.pdfSuppose Alice wants to send a message to Bob containing her name (N) a.pdf
Suppose Alice wants to send a message to Bob containing her name (N) a.pdf
 
Suppose a small economy produces only smart TVs- In year one- 100-000.pdf
Suppose a small economy produces only smart TVs- In year one- 100-000.pdfSuppose a small economy produces only smart TVs- In year one- 100-000.pdf
Suppose a small economy produces only smart TVs- In year one- 100-000.pdf
 
Sunland Corporation has income from continuing operations of $270-000.pdf
Sunland Corporation has income from continuing operations of $270-000.pdfSunland Corporation has income from continuing operations of $270-000.pdf
Sunland Corporation has income from continuing operations of $270-000.pdf
 
Sunvise Garden Center buys 375 bags of fertizer per month for leeding.pdf
Sunvise Garden Center buys 375 bags of fertizer per month for leeding.pdfSunvise Garden Center buys 375 bags of fertizer per month for leeding.pdf
Sunvise Garden Center buys 375 bags of fertizer per month for leeding.pdf
 
Succinate is transformed into oxaloacetate by a series of _______ reac.pdf
Succinate is transformed into oxaloacetate by a series of _______ reac.pdfSuccinate is transformed into oxaloacetate by a series of _______ reac.pdf
Succinate is transformed into oxaloacetate by a series of _______ reac.pdf
 
Summarize the internal control procedure of maintaining adequate recor.pdf
Summarize the internal control procedure of maintaining adequate recor.pdfSummarize the internal control procedure of maintaining adequate recor.pdf
Summarize the internal control procedure of maintaining adequate recor.pdf
 
Sum of scores Sum of squared scores Sample size Mean.pdf
Sum of scores       Sum of squared scores       Sample size       Mean.pdfSum of scores       Sum of squared scores       Sample size       Mean.pdf
Sum of scores Sum of squared scores Sample size Mean.pdf
 
SUBJECT- HIM204 Quality Assurance Explain what other different steps.pdf
SUBJECT- HIM204 Quality Assurance   Explain what other different steps.pdfSUBJECT- HIM204 Quality Assurance   Explain what other different steps.pdf
SUBJECT- HIM204 Quality Assurance Explain what other different steps.pdf
 
Subject- SUBJECT- COM101- HIMBC-AOS & COM201- CAMA There are several t.pdf
Subject- SUBJECT- COM101- HIMBC-AOS & COM201- CAMA There are several t.pdfSubject- SUBJECT- COM101- HIMBC-AOS & COM201- CAMA There are several t.pdf
Subject- SUBJECT- COM101- HIMBC-AOS & COM201- CAMA There are several t.pdf
 

Recently uploaded

Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
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
negromaestrong
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Recently uploaded (20)

psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
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
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
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
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
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
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet 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
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
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
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 

Here is the code- I can't get it to work- I need a function that finds.pdf

  • 1. Here is the code: I can't get it to work. I need a function that finds the maximum of two integers. #include <stdio.h> #include <stdlib.h> #include <limits.h> /* 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/n"); printf("--------------------------------------------n"); int i; for(i=0; i < total_processes; i++){ printf("%dt", table[i].id); printf("%dt", table[i].arrival); printf("%dt", table[i].total_cycles);
  • 2. printf("%dt", table[i].start); printf("%dt", table[i].end); printf("%dt", table[i].turnaround); } 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 */ int 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 < total_processes; i++){ int arrival = -1; int total_cycles = -1; printf("Enter process id: "); scanf("%d", &table[i].id); } 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;
  • 3. } /***************************************************************/ 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 < 1){ min_value = INT_MAX; if(table[i].done){ if(table[i].arrival < min_value){ min_value = 0; min_index = 0; } } /*for loop*/ table[min_index].start = max(current_cycle, table[min_index].arrival); table[min_index].end = table[min_index].start + table[min_index].total_cycles; table[min_index].turnaround = table[min_index].end - table[min_index].total_cycles; table[min_index].done = 1; current_cycle = table[min_index].end; done++;
  • 4. } print_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 */ int done = 0; int min_value; int current_cycle = 0; int min_index; int i; table[i].done = 0; while(done < 1){ min_value = INT_MAX; if(table[i].done == 0){ if((table[i].arrival < min_value) && (table[i].arrival <= current_cycle)){ min_value = 0; min_index = 0; } } table[min_index].start = 0; table[min_index].end = 0; table[min_index].turnaround = 0; table[min_index].done = 0;
  • 5. } done++; print_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 */ 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 < 1){ min_value = INT_MAX; if(table[i].done){
  • 6. if((table[i].total_remaining < min_value) && (table[i].arrival <= current_cycle)){ min_value = 0; min_index = 0; } } } 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 */
  • 7. /* call appropriate procedure based on choice--use switch statement or series of if, else if, else statements */ int choice; while(choice != 5){ printf("Batching Schedulingn"); printf("--------------------------n"); printf("1) Enter parametersn"); printf("2) Schedule processses with FIFO algorithmn"); printf("3) Schedule processes with SJF algorithmn"); printf("4) Schdule processes with SRT algorithmn"); printf("5) Quit and free memoryn"); printf("n"); printf("Enter selection: "); scanf("%d", &choice); printf("n"); 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
  • 8. 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...