Operating Systems (COMP2211)
Coursework 1: Shell implementation
Submission You must submit your work to the appropriate submission point on Gradescope.
You should submit a single file called mysh.c, any other files you submit will be ignored and
will not be marked.
Deadline See Gradescope submission date
Weighting This piece of summative coursework is worth 25% of the module grade.
Learning outcomes In this coursework you will demonstrate:
- An understanding of how processes are created by the operating system
- An understanding of file descriptors and their relationship to pipes and redirection.
- The ability to program components of an operating system.
In this coursework you will implement a simple shell for the Xv6 Operating System. The shell will
be implemented as a user space program. Before you attempt this coursework, ensure that you
have completed the “Operating System Interface” and “Operating System Organisation” directed
reading.
You should provide your implementation in a new file called mysh.c. You may use any helper
functions provided by the Xv6 kernel or user libraries. For each of the following items implement
the feature into your shell, as you progress the features to implement become hard. Your
implementation should not require you to modify any file other than mysh.c and Makefile.
Here are some simple instructions to get you started:
1. To start with create a file in the user directory for the Xv6 operating system source code
called mysh.c.
2. Insert the appropriate headers and a main function into your mysh.c.
3. Modify the Makefile to include your shell in the build process.
4. Test that your new executable is being included by running make qemu. You should be able
to execute your new program by typing mysh at the command prompt.
Continue to implement the following features.
1 Execute simple commands (5 Marks)
Implement the execution of simple commands. Your shell should be able to:
1. Prompt the user for a command by printing “>>>” as a command prompt.
2. Execute a command inputted to the command prompt.
3. Loop indefinitely until the shell is exited.
4. Handle the “cd” command (this is a special case so will need to be handled separately to
other commands, why?).
1
2 Input/Output redirection (6 Marks)
Implement Input/Output redirection. Your shell should be able to:
1. Handle two element redirections. For example,
echo "Hello world" > foo, or
cat < foo
3 Pipes (6 Marks)
Implement Pipes. Your shell should be able to:
1. Handle two element pipelines. For example,
ls | grep mysh, or cat README | grep github
4 Additional features (8 Marks)
Implement the following advanced features:
1. Implement multi element pipelines. For example,
ls | head -3 | tail -1
2. Implement non-trivial combinations of pipes and redirection. For example,
ls | head -3 | tail -1 > myoutput
3. Implement the “;” operator that allows a list of shell commands to be given and executed
sequentially.