Microsoft Word - 310Ass2Winter2021.docx Operating Systems COMP 310 – ECSE 427 McGill University Vybihal & Balmau Assignment #2 Page 1 of 8 Assignment #2: The Kernel and Process Execution Due: February...

2 answer below »
I have the assignment attached, and the link below is the reference solution I found online, please modify it so that I won't be detected as plagiarism.
This assignment is built based on the previous one, its solution is also in the link below.

https://github.com/Catosine/COMP310-ECSE427-Operating-System/tree/ec92eec14dff39225b75a7029a75d193a803eb02


Microsoft Word - 310Ass2Winter2021.docx Operating Systems COMP 310 – ECSE 427 McGill University Vybihal & Balmau Assignment #2 Page 1 of 8 Assignment #2: The Kernel and Process Execution Due: February 12, 2021 at 23:55 on myCourses 1. Preliminary Notes • The question is presented from a Linux point of view using the computer science server mimi.cs.mcgill.ca, which you can reach remotely using ssh or putty from your laptop (see lab 1). We suggest you do this assignment directly from mimi.cs.mcgill.ca since these are the computers the TA will be using. • Your solution must be built using the modular programming techniques we discussed in the in- class exercise sessions and the C labs. • You must write this assignment in the C Programming language. 2. Assignment Question: Building a Kernel 2.1 Overview: For this assignment, you will need the fully working OS Shell from Assignment 1. You can either build on top of your past submission, or use the official solution provided on myCourses. The goal of this assignment is to add one new command to your shell (detailed command description in Section 2.5): COMMAND DESCRIPTION exec prog1 prog2 prog3 Executes up to 3 concurrent programs provided as arguments High-level notes on exec command behavior: • exec takes one to three arguments. Each argument is the name of a different mysh script filename. For this assignment, exec does not permit us to launch multiple scripts with the same filename. If you try to do that your shell displays the error, “Error: Script already loaded” and all program script execution terminates. • If there is a load error, then no programs run. The user will have to input the exec command again. • To simplify the assignment, we will assume that “compiled” programs are the same as mysh scripts. We will reuse the shell’s interpreter to both run shell scripts and execute the kernel programs. A more detailed description follows in Section 2.5. Important: For simplicity, you are simulating a single core CPU, that does NOT support threading. We will also not be testing recursive exec calls. Even though you only need to add one command to the shell, this is a much more complex task than the previous commands in Assignment 1 (so start early, use your time wisely, and ask the TAs for guidance if you get stuck). To support this new command, you need to simulate the kernel run-time environment, which includes the PCB, the ready queue, the CPU scheduler, and a temporary simple memory (which we will upgrade in assignment 3). Operating Systems COMP 310 – ECSE 427 McGill University Vybihal & Balmau Assignment #2 Page 2 of 8 This rest of this document provides a description of the file structure in Section 2.2, compilation notes in Section 2.3, a description of the data structures and their behavior in Section 2.4, a description of the exec command and its behavior in Section 2.5, and a description of the scheduling algorithms in Section 2.6. 2.2 Your source files: Your entire application must contain the following source files: • shell.c, interpreter.c, and shellmemory.c, together with their respective .h files from Assignment 1. • kernel.c: This is the true home of the main() function in the OS, so you will move the main() function from shell.c to kernel.c. The kernel.c main() function calls the shell.c int shellUI() function (which is your previous main() function from Assignment 1), to display the command-line to the user. The kernel main() will also instantiate all the kernel data structures. • cpu.c: Contains data-structures and algorithms to simulate task switching. • pcb.c: Contains data-structures and helper functions for the process control blocks. • ram.c: Contains data-structures and helper functions for RAM simulation. Add .h files as you see fit. All source files must be built using modular programming techniques (see lab 2). 2.3 Compiling and running your kernel: Compile your application using gcc with the name mykernel. To do modular programming, you must compile your application in the following manner: gcc -c shell.c interpreter.c shellmemory.c kernel.c cpu.c pcb.c ram.c gcc -o mykernel shell.o interpreter.o shellmemory.o kernel.o cpu.o pcb.o ram.o To run your kernel, from the command line prompt type: ./mykernel Similar to the last assignment, mykernel will display: Kernel 1.0 loaded! Welcome to the shell! Shell version 2.0 Updated February 2021 $ As before, the dollar sign is the prompt of your fully functional shell from Assignment 1. From this prompt the user will type in their command and the shell will display the result from that command on the screen (or an error message), and then the dollar sign is displayed again prompting the next command. The user stays in this interface until they ask to quit. Operating Systems COMP 310 – ECSE 427 McGill University Vybihal & Balmau Assignment #2 Page 3 of 8 2.4 Kernel data structures: You will need to implement the following data structures: RAM, Ready Queue, PCB, and the CPU scheduler. 2.4.1. RAM Each program executed by the shell’s exec command is loaded into the RAM. This is not true for the mysh scripts, they are loaded and executed as in Assignment 1. The exec command runs programs concurrently, therefore the programs need to be in the RAM data structure at the same time. Implementation. RAM is implemented as array of char* pointers: char *ram[1000]; • The entire source file of each program is loaded into the ram[] array. • Each line from the source file is loaded into its own cell in the ram[] array. • This RAM has space for 1000 lines of code, from at most 3 programs at the same time (i.e., about 330 lines of code, on average, per program). • A NULL pointer indicates that there is no code at that cell location in ram[]. • A program is said to be in memory when all its lines of code are copied into the cells of the ram[] array. If there is not enough space to store all the lines in the script then the load terminates with an error message: “ERROR: Not enough RAM to add program.” Steps for loading a program P into RAM: 1. fopen the program P. 2. Find the next available cell in ram[]. 3. Copy all the lines of code into ram[]. Hint: To read a line from the program do fgets(file,buffer,limit); ram[k] = strdup(buffer); // k is the current line the program occupies in ram[]. 4. Remember the start cell number and the ending cell number of P’s location in ram[]. Hint: it helps to keep track of the next free cell in ram[] with “private” variables in ram.c. Steps for unloading a program P from RAM, when the program completed its execution: 1. For all the lines of code in ram[] occupied by P, do ram[k]=NULL; 2.4.2. Ready Queue Implementation. The ready queue is where the PCBs of processes that are ready to run are enqueued. This queue is used by the scheduler. In this assignment, the Ready Queue is FIFO and Round Robin (RR). Ready Queue is implemented as a linked list of PCBs, with head and tail pointers. Pointer “head” points to the first PCB in the list and pointer “tail” points to the last PCB in the list. • The first PCB is the one that gets the CPU. • New PCBs are appended at the tail. • Make sure to update “tail” to point to the new PCB after appending it to the list. Operating Systems COMP 310 – ECSE 427 McGill University Vybihal & Balmau Assignment #2 Page 4 of 8 2.4.3. PCB Implementation. For this assignment our PCB will be very simple. It will contain only three variables: a program counter (PC), the program’s start address, and the program’s ending address. PCB is implemented as a struct with three fields: struct PCB {int PC; int start; int end;}; • PC will be an integer number that refers to the cell number of ram[] containing the instruction to execute. Note 1: the PCB’s PC field is not the CPU instruction pointer, therefore it is updated only after a task switch. The PCB’s PC is updated after the quanta is finished (see Section 2.4.4. below). Note 2: when a program is launched its PCB is created and the PC field points to the first line of the program. • start contains the cell number of ram[] of the first instruction of the program. • end variable contains the cell number of ram[] of the last instruction of the program. 2.4.4. CPU Implementation. Our CPU is simulated by a struct having an instruction pointer (IP), instruction register (IR), and a quanta field. struct CPU {int IP; char IR[1000]; int quanta=2;} • IP is similar to the PCB PC field. IP points to the next instruction to execute from ram[]. • IR. The currently executing instruction is stored in the IR. IR stores the instruction that will be sent to the interpreter for execution. This simulates how the assembler instruction is loaded from RAM into the CPU’s Instruction Register. The interpreter() function simulates the CPU’s sequencer, which executes the instruction. • quanta represents the amount of time that each process executes before being switched out by the scheduler. For this assignment, we assume the quanta is equal to 2 lines of code for each program. Since we are not implementing threads, all concurrent programs access the same shell memory space. We are using the shell memory of Assignment 1 as one global memory space where all the scripts will read and write
Answered 3 days AfterFeb 12, 2021

Answer To: Microsoft Word - 310Ass2Winter2021.docx Operating Systems COMP 310 – ECSE 427 McGill University...

Sandeep Kumar answered on Feb 14 2021
124 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here