Need Help with this Question or something similar to this? We got you! Just fill out the order form (follow the link below), and your paper will be assigned to an expert to help you ASAP.
Added on: 0000-00-00 00:00:00Order Code: Question Task Id: 0
Operating System Assignment:
Simple Shell
Background
In this project, you will implement a command line interpreter or shell. The shell should operate in this basic way: when you type in a command (in response to its prompt), the shell creates a child process that executes the command you entered and then prompts for more user input when it has finished.
The shell you implement will be similar to, but much simpler than, the one you run every day in Unix. You can find out which shell you are running by typing echo $SHELL at a prompt. You may then wish to look at the man pages for the shell you are running (most likely bash) to learn more about its functionalities. For this project, you need to implement only some as specified below.
Part 1: The Simple Shell
1. Your shell executable should be named mysh. Your shell source code should be in mysh.c,
2. The shell should run continuously, and display a prompt when waiting for input.
The prompt should be EXACTLY ‘$’. No spaces, no extra characters. Example with a command:
$/bin/ls -l
3. Your shell should read a line from stdin one at a time. This line should be parsed out into a command and all its arguments. In other words, tokenize it.
A. You may assume that the only supported delimiter is the whitespace character (ASCII character number 32).
B. You do not need to handle “special” characters. Do not worry about handling quotation marks, backslashes, and tab characters. This means your shell will be unable to support arguments with spaces in them. For example, your shell will not support file paths with spaces in them.
C. You may set a reasonable maximum on the number of command line arguments, but your shell should handle input lines of any length.
4. After parsing the command, your shell should execute it. A command can either be a reference to an executable OR a built-in shell command (see Part 2). For Part 1, just focus on running executables, and not on built-in commands.
A. Executing commands that are not shell built-ins and are just the executable name (and not a full path to the executable) is done by invoking fork() and then invoking exec().
B. You may NOT use the system() function, as it just invokes the /bin/sh shell to do all the work.
Part 2: Implement Built-in Commands: exit, cd, history
1. exit – Simply exits your shell after performing any necessary clean up.
2. cd [dir] – Short for “change directory”, and will be used to change the current working directory of your shell. Do not worry about implementing the command line options that the real cd command has in Bash. Just implement cd such that it takes a single command line parameter: The directory to change to.
3. history [-c] [offset] – Similar to the Bash built-in history command, but much simpler.
A. history (without arguments) displays the last 100 commands the user ran, with an offset next to each command. The offset is the index of the command in the list, and valid values are 0 to 99, inclusive. 0 is the oldest command. Do not worry about persisting this list to a file; just store it in memory. Once more than 100 commands are executed, remove the oldest entry from the list to make room for the newer commands. Note that history is also a command itself and therefore should also appear in the list of commands. If the user ran invalid commands, those should also appear in the list.
B. history -c clears the entire history, removing all entries. For example, running history immediately after history -c should show history as the sole entry in the list.
C. history [offset] executes the command in history at the given offset. Print an error message of your choosing if the offset is not valid.
D. Example output for built-in history:
E. $cd /home/w4118
F. $/bin/ls
G. my_file.txt
H. $history
I. 0 cd /home/w4118
J. 1 /bin/ls
K. 2 history
L. $history 1
M. my_file.txt
N. $history
O. 0 cd /home/w4118
P. 1 /bin/ls
Q. 2 history
R. 3 history 1
S. 4 history
T. $history -c
U. $history
W. 0 history$
Uploaded By : jack
Posted on : February 07th, 2018
Downloads : 0