assignment03-multilevelQueueScheduler.pdf CS2123 Data Structures - Fall 2018 Assignment 3: multilevelQueueScheduler Due 10/8/18 by 11:59pm In this assignment you will be simulating some of the work...

I am a second year college student. I have taken Intro to Programming I (Java) and Intro to Programming II (C). This assignment is for CS2123 Data Structures. I am not the best programmer, so the code should be as basic as possible. Attached is a zip containing all the necessary files. The .pdf is the instructions.


assignment03-multilevelQueueScheduler.pdf CS2123 Data Structures - Fall 2018 Assignment 3: multilevelQueueScheduler Due 10/8/18 by 11:59pm In this assignment you will be simulating some of the work performed by an operating system (albeit at a super high level). Specifically you will track the simulated processes that currently need to run and then schedule them to run on the CPU according to a given set of rules. Introduction Each process has: • an identifier • a number of time cycles needed to run • an array of data that belongs to that process • a priority of either FOREGROUND or BACKGROUND • you can add other data that you think will help in simulating the schedule. Code: scheduleProcess (5 points) You are passed a process identifier and priority to add to the appropriate queue. Code: simulateTimeStep (10 points) Simulates running one time step of a process. The process to simulate will be chosen based on the following rules: (1) As long as there are FOREGROUND tasks no BACKGROUND task is run. (2) Rules for running FOREGROUND processes: (a) Store the FOREGROUND processes in a queue. (b) The queue follows a round-robin schedule scheme. In particular, after the process at the front of the queue runs for 5 cycles it is moved to the back of the queue. (3) Rules for running BACKGROUND processes: (a) Store the BACKGROUND processes in a queue. (b) The queue follows a FCFS (first-come, first-serve) schedule scheme. In particular, the first process added to the BACKGROUND queue will be fully processed before any of the other processes in the queue are processed. (c) If a process has remained in the BACKGROUND queue for 50 cycles or longer it is moved to the rear of the FOREGROUND queue. (4) The process will return the name of another process or NULL. Either way you should return this back to the calling function. Analysis: Priority Queue (2 points) • What is the asymptotic runtime of your scheduleProcess? • What is the asymptotic runtime of your simulateTimeStep? Analysis: Priority Queue (3 points) Suppose we combined the FOREGROUND and BACKGROUND queues from part one into a single priority queue. • Would the asymptotic runtime of scheduleProcess be increased, decreased, or say the same? • Specifically, what is the new asymptotic runtime of scheduleProcess? • Justify your reasoning for this runtime in one to two sentences. The an- swer depends on how you setup your priority queue so this justification is critical. Deliverables: Your solution to the code portion of the assignment should be submitted as “multilevelQueueScheduler.c”, “multilevelQueueScheduler.h”, and “process.h”. The analysis portion should be submitted as separate .pdf file. Upload these file to Blackboard under Assignment 3. Do not zip your files. To receive full credit, your code must compile and execute. You should use valgrind to ensure that you do not have any memory leaks. Getting started: The code provided by the instructor is deliberately obtuse (especially “processSimulator.c”). You should focus less on what her code specifically does and more on where to call the code in your functions (hints to this were given in the function comment headers so be sure to read them). When in doubt try running your code! Don’t be afraid to add print state- ments to help you better understand what data is being stored in a struct or passed by a function. Remember: The program you submit should be the work of only you. Cheating will be reported to judicial affairs. Both the copier and copiee will be held responsible. assignment03-multilevelQueueScheduler.tex \documentclass[12pt]{elsart} \usepackage{amsmath} \usepackage{amssymb} \usepackage{color} \usepackage{graphicx} \newcommand{\field}[1]{\mathbb{#1}} \usepackage{graphicx} \usepackage{hyperref} \usepackage{algorithm} \usepackage{algpseudocode} \usepackage{enumitem} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Space to make more readable! %\vspace{10 mm} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Take out later! %\usepackage[letterpaper,top=0.75in, bottom=0.75in, left=1in, right=1in]{geometry} \begin{document} \pagestyle{empty} \begin{center} \Large CS2123 Data Structures - Fall 2018 \\ \large {\bf Assignment 3: multilevelQueueScheduler}\\ \normalsize Due 10/8/18 by 11:59pm \end{center} In this assignment you will be simulating some of the work performed by an operating system (albeit at a super high level). Specifically you will track the simulated processes that currently need to run and then schedule them to run on the CPU according to a given set of rules. {\bf Introduction} Each process has: \begin{itemize} \item an identifier \item a number of time cycles needed to run \item an array of data that belongs to that process \item a priority of either FOREGROUND or BACKGROUND \item you can add other data that you think will help in simulating the schedule. \end{itemize} {\bf Code: scheduleProcess (5 points)} You are passed a process identifier and priority to add to the appropriate queue. {\bf Code: simulateTimeStep (10 points)} Simulates running one time step of a process. The process to simulate will be chosen based on the following rules: \begin{enumerate} \item As long as there are FOREGROUND tasks no BACKGROUND task is run. \item Rules for running FOREGROUND processes: \begin{enumerate} \item Store the FOREGROUND processes in a queue. \item The queue follows a round-robin schedule scheme. In particular, after the process at the front of the queue runs for 5 cycles it is moved to the back of the queue. \end{enumerate} \item Rules for running BACKGROUND processes: \begin{enumerate} \item Store the BACKGROUND processes in a queue. \item The queue follows a FCFS (first-come, first-serve) schedule scheme. In particular, the first process added to the BACKGROUND queue will be fully processed before any of the other processes in the queue are processed. \item If a process has remained in the BACKGROUND queue for 50 cycles or longer it is moved to the rear of the FOREGROUND queue. \end{enumerate} \item The process will return the name of another process or NULL. Either way you should return this back to the calling function. \end{enumerate} \newpage {\bf Analysis: Priority Queue (2 points)} \begin{itemize} \item What is the asymptotic runtime of your scheduleProcess? \item What is the asymptotic runtime of your simulateTimeStep? \end{itemize} {\bf Analysis: Priority Queue (3 points)} Suppose we combined the FOREGROUND and BACKGROUND queues from part one into a single priority queue. \begin{itemize} \item Would the asymptotic runtime of scheduleProcess be increased, decreased, or say the same? \item Specifically, what is the new asymptotic runtime of scheduleProcess? \item Justify your reasoning for this runtime in one to two sentences. The answer depends on how you setup your priority queue so this justification is critical. \end{itemize} {\bf Deliverables:} Your solution to the {\bf code} portion of the assignment should be submitted as ``multilevelQueueScheduler.c", ``multilevelQueueScheduler.h'', and ``process.h''. The {\bf analysis} portion should be submitted as separate .pdf file. Upload these file to Blackboard under Assignment 3. {\bf Do not zip your files}. To receive full credit, your code must compile and execute. You should use valgrind to ensure that you do not have any memory leaks. {\bf Getting started:} The code provided by the instructor is deliberately obtuse (especially \\``processSimulator.c''). You should focus less on what her code specifically does and more on where to call the code in your functions (hints to this were given in the function comment headers so be sure to read them). When in doubt {\bf try running your code!} Don't be afraid to add print statements to help you better understand what data is being stored in a struct or passed by a function. {\bf Remember: The program you submit should be the work of only you. Cheating will be reported to judicial affairs. Both the copier and copiee will be held responsible.} \end{document} driverSimOS.c #include #include #include #include #include #include #include "queue.h" #include "multilevelQueueScheduler.h" #include "processSimulator.h" void testFile( const char dataFile[], char *(*f)( char *)); int getRuntime(char* processName); priority getPriority(char* processName); int main( int argc, char *argv[] ) { int i = 0; char *testData[] = {"B|LNG|00|10|7|03|00","F|SMP|00|30|08|31|00","F|RPD|00|09|03|32|00","F|VID|00|40|99|01|00"}; schedule *ps = initializeSchedule(); char *name; //Schedule testData for( i=0; i<4; i++){="" name="(char" *)malloc(strlen(testdata[i])+1);="" if(="" name="=NULL" ){="" fprintf(stderr,="" "main:="" allocation="" of="" memory="" failed.");="" exit(-1);="" }="" strcpy(="" name,="" testdata[i]="" );="" scheduleprocess(="" ps,="" name,="" getruntime(name),="" getpriority(name)="" );="" }="" simulate="" time="" steps="" until="" no="" process="" is="" still="" running="" while(="" unfinishedschedule(="" ps="" )="" ){="" name="simulateTimeStep(" ps="" );="" if(="" name!="NULL" )="" scheduleprocess(="" ps,="" name,="" getruntime(name),="" getpriority(name)="" );="" }="" freeschedule(="" ps="" );="" return="" 0;="" }="" int="" getruntime(char*="" processname){="" char="" runtimestring[3];="" int="" runtime;="" int="" p="abs((int)getPriority(processName)-1);" read="" runtime="" from="" the="" 4th="" |-separated="" value="" in="" the="" string="" sscanf(processname,="" "%*[^|]|%*[^|]|%*[^|]|%[^|]",="" runtimestring);="" sscanf(runtimestring,="" "%d",="" &runtime);="" return="" max(runtime/powint(2,p),1);="" }="" priority="" getpriority(char*="" processname){="" return="" processname[0]="='B';" }="" hw3-exampleexecution.rtf="" fox01:~/documents/fall2018/hw3=""> make gcc -Wall -g -c driverSimOS.c gcc -Wall -g -c queue.c gcc -Wall -g -c processSimulator.c gcc -Wall -g -c multilevelQueueScheduler.c gcc -Wall -g -o driverSimOS driverSimOS.o queue.o processSimulator.o multilevelQueueScheduler.o fox01:~/Documents/Fall2018/HW3> valgrind --leak-check=full ./driverSimOS ==29682== Memcheck, a memory error detector ==29682== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. ==29682== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info ==29682== Command: ./driverSimOS ==29682== Process data created: LNG-0 (BACKGROUND for 10 cycles) Process data created: SMP-0 (FOREGROUND for 15 cycles) Process data created: RPD-0 (FOREGROUND for 4 cycles) Process data created: VID-0 (FOREGROUND for 20 cycles) 0 - Running process: SMP-0 1 - Running process: SMP-0 2 - Running process: SMP-0 3 - Running process: SMP-0 4 - Running process: SMP-0 5 - Running process: RPD-0 6 - Running process: RPD-0 7 - Running process: RPD-0 Process data created: RPD-1 (FOREGROUND for 2 cycles) 8 - Running process: RPD-0 Process data deleted: RPD-0 (ran for 4 cycles) 9 - Running process: VID-0 10 - Running process: VID-0 11 - Running process:
Oct 05, 2020
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here