Principles of Operating Systems

CMSC 421 — Spring 2020


Homework 1

50 points

Due by 11:59PM EST on Sunday, February 23, 2020

CHANGELOG

February 10: Removed quotes around example and fixed program name in parsing example.

Complete the following programming assigment and submit your code using the GitHub repository that you will have created for this assignment. This assignment must be completed in the C programming language (you can choose to use C89/C90/ANSI C, C99, or C11 (with POSIX extensions) as you see fit — please don't try to torture yourself with pre-ANSI/traditional/K&R C).

The projects assigned in this class all involve programming within the Linux kernel in the C programming language. Many students in this class over the past several years have expressed that their experience with programming in C is, unfortunately, somewhat lacking. This lack of experience with C can lead to students having significant difficulty completing the programming projects assigned successfully. To that end, this homework assignment is designed to help you get a bit of a warm-up with C, including topics that will be of extreme importance going forward with your programming projects. This assignment is to be completed entirely in user-space — not within the Linux kernel source code and does not involve recompiling the kernel. You may complete this assignment outside of your VM for the class if you wish, however the TAs will be using a setup like your VM in order to grade the assignment (so you should at least compile/run your submitted assignment once in your VM to ensure it works before submitting it). You are however not allowed to use the GL system at UMBC to complete this assignment!

You may be expected to revisit/revise/extend the program you produce for this assignment in later homework assignments this semester. To this end, you should strive to produce an program that you will be able to easily pick back up later in the semester and add more functionality to it. It is in your best interests to ensure that the program you produce for this assignment works well and fulfills all of the requirements outlined herein.

In this assignment, you will be producing a simple *nix shell program. This assignment only requires a few very basic features of a shell, and leaves out much of the functionality that more advanced shells such as Bash include. That is not to say that this assignment will be easy — this is a 400-level course, after all. There are still several parts of this assignment that could trip you up, especially if you are not comfortable with lower-level C programming.

For this assignment, you will only need to support a few very basic features of a full-fledged *nix shell. Specifically, you will need to have support for all of the following:

You are not expected to support any of the following features, however these may or may not be added in a future homework assignment.

Your shell program is not allowed to use any external libraries other than the system's C library. Do not try to use libraries like Readline. You will lose points for using external libraries to implement shell functionality! You are not allowed to use any of the following functions in the C library to implement your shell:

On the other hand, the following list of functions may prove to be very useful to you, depending on how you you implement your shell:

Additionally, a file of potentially useful functions has been provided for this assignment by one of the instructors of the course. You may find this file here along with a header (.h) file here. Particularly useful in this code is a are the functions unescape (which removes escape sequences and quotes from strings) and first_unquoted_space which will tell you the location of the next space in the string that is not quoted or part of an escape sequence. You are not required to use this code in your shell if you would rather implement this part yourself. If you do use this code in your shell, be sure to add the file to your git repository, just like any other source code you write.

You are not allowed to implement any of your shell's functionality by calling on another shell to do the work. You must do the argument parsing and calling of programs in your own code!

When submitting your shell program, please be sure to include the source code of the shell program (in one or more C source code files), as well as a Makefile that can be used to build the shell. Your shell must be able to be built and run on a VM as has been set up for this course in your projects. Also, you should include a README file describing your approach to each of the requirements outlined above. Additionally, your program must be compiled to a binary called simple_shell with the Makefile you provide.

If you would like a template for use as a Makefile for your shell, I have provided one here.

To submit your project, you must first accept the assignment on GitHub. The link to do so is posted on the course Piazza. Once you have done that, make sure that your project files (any source files and your Makefile) are in their own directory, then run the following commands in that directory (substituting the list of files you need to commit for your_files_go_here and your GitHub username for username, of course):

git init
git add your_files_go_here
git commit
git remote add origin git@github.com:umbc-cmsc421-sp2020/shell-username.git
git push -u origin master

git tag hw1
git push origin --tags

Hints

The code that is provided to you is very useful. It is highly suggested that you use it in your shell.

The first_unquoted_space function provided can greatly ease the work of parsing a string into arguments. For instance, on the input /bin/echo "Hello World", the function would return 9, which is the index of the first space. If run on the remainder of the string after that space, it would return -1, telling you that there are no further spaces in the string that are not quoted.

The unescape function allocates memory. If it returns non-NULL, you must free the value that it returns. Additionally, the second argument to unescape should probably always be stderr.

Yes, you can lose points on this assignment for memory leaks. A shell is intended to be a long-running program and thus it is very important not to leak memory. Also, this is meant to provide practice for your later projects in the course, where memory leaks can be very problematic.


Last modified Monday, 10-Feb-2020 17:58:19 EST