$29
Assignment #1 The Operating System Shell
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). If you do this assignment from an MS Windows machine, then make sure to provide the DLL libraries your program uses (if any) so that the TA can run it from their MS Windows machine. It is not the TA’s responsibility to make your program run. The TAs will not debug your program.
You must write this assignment in the C Programming language.
Assignment Question: Building an OS Shell
Your source files:
Your entire application must be built from three c files: shell.c, interpreter.c, and shellmemory.c. These three source files must be built using modular programming techniques (see lab 2). The file shell.c is the primary programming file. It contains the main() and parse() functions. The file interpreter.c contains the interpreter() function. Each command the interpreter() function accepts has a corresponding function that implements the command’s functionality. Give the function the same name as the command. The file shellmemory.c contains the private data structures and public functions that implement the shell memory (lab 2 will also be helpful here).
Compiling your shell:
Compile your application using gcc with the name mysh. To do modular programming, you must compile your application in the following manner: gcc -c shell.c interpreter.c shellmemory.c gcc -o mysh shell.o interpreter.o shellmemory.o
Running your shell:
From the command line prompt type: ./mysh
What mysh displays to the user:
Welcome to the <your name goes here shell! Version 1.0 Created January 2019 $
The above dollar sign is the prompt. The cursor flashes beside the prompt waiting for the user’s input. 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.
The command line syntax for your shell is : COMMAND ARGUMENTS.
Operating Systems COMP 310 – ECSE 427 McGill University
Vybihal Assignment #1 Page 2 of 4
Each command line command is a single line of text (a string) separated by spaces and terminated by a carriage return. Some commands are a single word, while other commands contain multiple words. Your shell processes each command similarly to how it was presented in class. You do not need to follow the class slides exactly.
The commands supported by mysh:
The commands are case sensitive.
COMMAND DESCRIPTION
help Displays all the commands quit Exits / terminates the shell with “Bye!” set VAR STRING Assigns a value to shell memory print VAR Prints the STRING assigned to VAR run SCRIPT.TXT Executes the file SCRIPT.TXT
There are no other commands (for now).
If the user inputs an unsupported command the shell displays “Unknown command”.
The command set VAR STRING first checks to see if VAR already exists. If it does exist, STRING overwrites the previous value assigned to VAR. If VAR does not exist, then a new entry is added to the shell memory where the variable name is VAR and the contents of the variable is STRING. For example: set x 10 creates a new variable x and assigns to it the string 10. Another example: set name Bob creates a new variable called name with string value Bob. Another example: set x Mary, replaced the value 10 with Mary.
The command print VAR first checks to see if VAR exists. If it does not exist, then is displays the error “Variable does not exist”. If VAR does exist, then is just prints the STRING. For example: print x from the above example will display Mary.
The command run SCRIPT.TXT assumes that a text file exists with the provided file name. It opens that text file and then sends each line one at a time to the interpreter (as seen in class). The interpreter treats each line of text as a command. Each line affects the shell and the UI. At the end of the script, the file is closed, and the command line prompt is displayed once more. For example: run test.txt will begin by opening the file test.txt. If that fails, then an error message is displayed: “Script not found”. If the file is opened, then each line of the file is interpreted. At the end, the file is closed, and the command line prompt is displayed.
Testing your shell:
The TAs will use and modify the provided text file to test your shell. You can also use this file to test your shell or you can test it the old fashion way by typing input from the keyboard. To use the provided text file, you will need to run your program from the OS command line as follows:
$ ./mysh < testfile.txt
Operating Systems COMP 310 – ECSE 427 McGill University
Vybihal Assignment #1 Page 3 of 4
Each line from testfile.txt will be used as input for each prompt your program displays to the user. Instead of typing the input from the keyboard the program will take the next line from the file testfile.txt as the keyboard input.
Make sure your program works in the above way.
WHAT TO HAND IN
Your assignment has a due date plus two late days. If you choose to submit your assignment during the late days, then your grade will be reduced by -5% per day. Submit your assignment to the assignment #1 submission box in myCourses. You need to submit the following: • A README.TXT file stating what OS you used: mimi.cs.mcgill.ca or MS Windows and any other special instructions you think the TA needs to know to run your program. • Your version of TESTFILE.TXT. This will be you telling the TA that you know for sure that your program can at least do the following. The TA will run your program with this file and they will also run it with their own version of the file. • Submit shell.c, interpreter.c and shellmemory.c (you may want to create .h files, if so, please hand those in as well) • Submit the executable (compiled on the appropriate machine). • If you used MS Windows and you used a DLL then upload those as well.
You must submit your own work. You can speak to each other for help but copied code will be handled as to McGill regulations.
HOW IT WILL BE GRADED
Your assignment is graded out of 20 points and it will follow this rubric: • The student is responsible to provide a working solution for every requirement. • The TA grades each requirement proportionally. This means, if the requirement is only 40% correct (for instance), then the student receives only 40% of the points assigned to that requirement. • Your program must run to be graded. If it does not run, then the student receives zero for the entire assignment. If your program only runs partially or sometimes, you should still hand it in. You will receive partial points. • The TA looks at your source code only if the program runs (correctly or not). The TA looks at your code to verify that you (A) implemented the requirement as requested, and (B) to check if the submission was copied. • Mark breakdown: o 1 point - Source file names. The TA must verify that the student created the three source files shell.c, interpreter.c and shellmemory.c as the only source files in the application. In addition the source files must be populated with at least what was specified in the assignment description for each file. The student is permitted to supply additional helper functions as they see fit, as long as it does not hinder the assignment requirements.
Operating Systems COMP 310 – ECSE 427 McGill University
Vybihal Assignment #1 Page 4 of 4
o 2 points - Modular programming. If the student wrote their application using modular programming techniques as described in lab 2 (or seen from another course) then they receive these points. o 1 point - Executable named mysh. The students compiled program must be named mysh. o 2 points - Shell UI as specified. See the assignment specification for the opening UI screen layout, the error messages, and the general flow of the application as described. For example, prompts are displayed continually until the user exits the application using the quit command. o 1 points - The help command. Displays all the command and description as seen in the assignment description. o 1 points - The quit command. Terminates the application. Prints “Bye!” and returns the user to their OS. o 3 points - The set command. Creates or overwrites a variable with the new string. o 3 points - The print command. Displays the string or the error message. o 4 points - The run command. Executes a text file of valid or invalid commands. o 2 points - Program can be tested with the TESTFILE.TXT file