Search for question
Question

Programming Assignment 1: Shell CSE3320 Description In this assignment you will write your own shell program, Mav shell (msh), similar to bourne shell (bash), c-shell (csh), or korn shell (ksh). It will accept commands, fork a child process and execute those commands. The shell, like csh or bash, will run and accept commands until the user exits the shell. Your file must be named msh.c Functional Requirements Requirement 1: Your program will print out a prompt of msh> when it is ready to accept input. It must read a line of input and, if the command given is a supported shell command, it shall execute the command and display the output of the command. ●● Code - tbakker@omega:~/msh_solution - ssh tbakker@omega.uta.edu - 100x24 [[tbakker@omega msh_solution]$ ./msh [msh> ls hello hello.c loop loop.c Makefile msh msh.c msh.o msh> Requirement 2: If the command is not supported your shell shall print the invalid command followed by ": Command not found.” ●●● [[tbakker@omega msh_solution]$ ./msh [msh> ls hello hello.c loop loop.c Makefile msh msh.c msh.o [msh> lss lss: Command not found. msh> Code - tbakker@omega:~/msh_solution - ssh tbakker@omega.uta.edu - 100x24 Requirement 3: [This requirement is removed.] Requirement 4: After each command completes, your program shall print the msh> prompt and accept another line of input. Requirement 5: Your shell will exit with status zero if the command is “quit” or “exit”. Requirement 6: If the user types a blank line, your shell will, quietly and with no other output, print another prompt and accept a new line of input. Code - tbakker@omega:~/msh_solution - ssh tbakker@omega.uta.edu - 100×24 [[tbakker@omega msh_solution]$ ./msh [msh> ls hello hello.c loop loop.c Makefile msh msh.c msh.o [msh> lss lss: Command not found. [msh> ls -ijh ls: invalid option - j Try `ls --help' for more information. Imsh> msh> [msh> [msh> msh> ] ] 1 Requirement 7: Your version of Mav shell shall support up to 10 command line parameters in addition to the command. Requirement 8: Your shell shall support and execute any command entered. Any command in /bin, /usr/bin/, /usr/local/bin/ and the current working directory is to be considered valid for testing. Your shell shall search the following PATH at minimum: 1. Current working directory, 2. /usr/local/bin 3. /usr/bin 4. /bin Parameters may also be combined. For example, ps may be executed as: ps -aef or ps -a -e -f Requirement 9: Mav shell shall be implemented using fork (), wait () and one of the exec family of functions. Your Mav shell shall not use system (). Use of system () will result in a grade of 0. Requirement 10: Your shell shall support the cd command to change directories. Your shell must handle cd .. Code - tbakker@omega:~/msh_solution - ssh tbakker@omega.uta.edu - 100×24 [[tbakker@omega msh_solution] $ msh [msh> ls hello hello.c loop loop.c Makefile msh msh.c msh.o [msh> mkdir foo [msh> cd foo [msh> ls [msh> cd .. [msh> ls foo hello hello.c loop loop.c Makefile msh msh.c msh.o msh> Requirement 11: Your shell shall support the pidhistory command to list the PIDs of the last 15 processes spawned by your shell. If there have been less than 15 processes spawned then it shall print only those process PIDs Requirement 12: Your shell shall support the history command which will list the last 15 commands entered by the user. Typing !n, where n is a number between 0 and 14 will result in your shell re-running the nth command. If the nth command does not exist then your shell will state “Command not in history.”. The output shall be a list of numbers 0 through n-1 and their commands, each on a separate line, single spaced. hello hello.c [msh> mkdir foo [msh> cd foo [msh> ls [msh> cd .. [msh> ls Code - tbakker@omega:~/msh_solution - ssh tbakker@omega.uta.edu 100x24 loop loop.c Makefile msh msh.c msh.o foo hello hello.c loop loop.c Makefile msh msh.c msh.o [msh> showpids 0: 7898 1: 7907 2: 7923 3: 7937 [msh> history 0: ls 1: mkdir foo 2: cd foo 3: ls 4: cd.. 5: ls 6: showpids 7: history [msh> !5 foo hello hello.c loop loop.c Makefile msh msh.c msh.o msh> If there are less than 15 commands in the history only list the commands the user has entered up to that point. Requirement 13: [This requirement is removed.] Requirement 14: Tabs or spaces shall be used to indent the code. Your code must use one or the other. All indentation must be consistent. Requirement 15: No line of code shall exceed 100 characters. Requirement 16: Each source code file shall have the following header filled out: /* Name: Student Name 10000001 ID: */ Rec ment 17: All code must be well commented. This means descriptive comments that tell the intent of the code, not just what the code is executing. The following are poor comments. // Set working_str equal to strdup return char *working_str = strdup( cmd_str); // Set working_root equal to working_str char *working_root = working_str; The following explains the intent: // Save a copy of the command line since strsep // will end up moving the pointer head char *working_str = strdup( cmd_str ); // we are going to move the working_str pointer so // keep track of its original value so we can deallocate // the correct amount at the end char *working_root = working_str; When in doubt over comment your code. Requirement 18: Keep your curly brace placement consistent. If you place curly braces on a new line, always place curly braces on a new end. Don't mix end line brace placement with new line brace placement.