Chapter 5
Week 4: Creating a small shell interface You must submit your work to the appropriate submission point in Gradescope, which willbe automatically marked. You should submit a single file called my_shell.c. Any otherfiles you submit will not be marked. Although you do not need to include any additionalsupporting documentation or report, we do expect that yourcode is well written, tested andcommented.
Deadline: Week 6 of teaching. Thursday. 7th of Novem
ber, 2024. 14:00. Extensions of up to 7 days are available.
Weighting: 40% of the final module mark.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.
Exercise
In this coursework you will implement a simple shell for the xv6 operating system. Thisnew shell will be implemented as a user space program. Before you attempt this coursework,make sure you have gone through most of the formative assessment exercises in the precedingweeks and convinced yourself that you know how various parts work. Where you have doubts,read relevant parts again and redo the coursework, which will make you spot new things andgain a deeper understanding of the material. You should provide your implementation in anew file called my_shell.c. You may use any helper functions provided by the xv6 kernel oruser libraries. For each of the following items implement the feature into your shell, as youprogress the features to implement become harder. This exercise should not require you tomodify any file other than my_shell.c and the Makefile.To start with clone the repository containing the starting code and copy my_shell.cfrom it into your xv6 user/ directory:29$ git clone https://github.com/mmikaitis/COMP2211-shell-template.gitModify the Makefile accordingly and rebuild xv6. It will not compile because my_shell.c isnot finalised yet. However, it also contains some commentsthat should help in finishing thentended structure. Your task is to finish writing methods getcmd, run_command, and main,by inserting code in the indicated locations. No other methods should be developed.You are allowed to look at a default xv6 shell source code as well aslearn about implementing shells using external resources. However,you are required to follow the unique structure outlined in the template and are not allowed to supply any code which was not developedsolely by yourself, starting from design stage. If you depend highlyon some online tutorials then you need to declare the sources in thecomments, which includes large language models. If you discuss earlyideas with someone in the lab you should make sure that you don’tend up with similar code structure; you should not code together.Gradescope willrun a similarity check of your submission and if thelogic of the new code is reported to be similar to someone else’s,the submission will be carefully checked manually and reported asacademic integrity violation if required. See this website for somedetail. The similarity check is resilient to changing variables namesor adding comments and new lines.Going through academic integrity interviews is a daunting process andmay result in severe delays to your degree progression. It is betterto submit nothing than submit the code that was partially developedby others. Ifyou are behind, speak to the lab demonstrators and themodule lead for guidance on best ways forward.
Part 1: Execute simple commands (5 Marks) Implement the execution of simple commands. Your shell should be able to:
- Prompt the user for a command by printing “>>>” as a command prompt.
- Execute a command inputted to the command prompt.
- Loop indefinitely until the shell is exited.
- Handle the “cd” command—you will notice that this command will need to be treatedas a special case.Do not forget to stress-test your simple shell before moving on to advanced features. Theautomatic marking will be testing it on various cases and marks will be deducted if it doesnot work when the same command is provided in a different format, such as with extra30spacing. For example, consider (note the amountandlocation of space characters whichmay 代写COMP2211A small shell interface impact the shell if they are not detected):
$ echo hello world
$ echo hello worldOnce you are comfortable that you have tested your shell with any possible command thatcould reveal bugs, move on to implement the following advanced features.
Part 2: Input/Output redirection (6 Marks)
Implement Input/Output redirection. Your shell should be able to handle two elementedirections. For example,
$ echo "Hello world" > temp
$ cat < temp
Part 3: Pipes (6 Marks) Implement pipes. Your shell should be able to handle two element pipelines. For example,
$ cat README | grep github
Part 4: Additional features (8 Marks) Implement the following advanced features:
- Implement multi-element pipelines. For example,$ ls | grep test | cat
- Implement non-trivial combinations of pipes and redirection. For example,$ ls | grep test | cat > myoutput
- Implement the “;” operator that allows a list of shell commands to be given andexecuted sequentially.$ ls | grep test | cat > myoutput; cat myoutput
Marking
Gradescope will run 26 test commands and award a mark out of 25. The commands that willbe run are not disclosed and you are required to usecreativity to think of various scenarioswhich may break your shell and test it thoroughly before submitting. 3 out of 25 marks31will be awarded to those who spot three especially tricky cases of specifying commands andimplement their shells to get around them.There are many ways to type commands, some straightforward as shown above, andsome not, such as when people type commands without usingany spaces or with arbitrary
number of spaces in various places. Your shell should be resilient to this ambiguity inspecifying commands. Those students who spent more time inthinking about various testcases and check them will get more marks than those who only try a few straightforwardcommands listed above.Here are a few example commands running in the new completed shell to get you started:xv6 kernel is booting
hart 2 starting
hart 1 starting
init: starting sh
>>> echo hellohello
>>> cat README | grep xv6xv6 is a re-implementation of Dennis Ritchie’s and Ken Thompson’s Unix
Version 6 (v6). xv6 loosely follows the structure and style of v6,xv6 is inspired by John Lions’s Commentary on UNIX 6th Edition (Peer
(kaashoek,[email protected]). The main purpose of xv6 is as a teaching>>> cat README| grep xv6xv6 is a re-implementation of Dennis Ritchie’s and Ken Thompson’s UnixVersion 6 (v6). xv6 loosely follows the structure and style of v6,xv6 is inspired by John Lions’s Commentary on UNIX 6th Edition (Peer(kaashoek,[email protected]). The main purpose of xv6 is as a teaching
>>>
It is worth to note that the default xv6 does not pass all of our expected tests. Fort only my_shell.c. See Minerva.34
标签:commands,shell,should,will,COMP2211A,command,small,xv6 From: https://www.cnblogs.com/comp9321/p/18535301