Question
Operating Systems Objective The purpose of this assignment is to get everyone up to speed on system programming and to gain some familiarity with the
Operating Systems
Objective
The purpose of this assignment is to get everyone up to speed on system programming and to gain some familiarity with the system call interface. A secondary goal is to use some of the programming tools provided in the UNIX environment. In this assignment you are to implement a UNIX shell program. A shell is simply a CLI program that conveniently allows you to run other programs. Read up on your favorite shell (such as bash, csh, tcsh, sh, ...) to see what it does..
Description
Basic Commands: The input to guish is a sequence of commands, each provided on a separate line of input text (or typed interactively at the keyboard). The following command must be supported:
progname [args]
Runs the program progname with the given, possibly optional, arguments.
exit
The exit internal command causes the shell to exit. This is the *only* way your shell can exit. Just prior to your shell exiting, you should print out the number of times each interrupt was detected.
hist
The hist history internal shell command will display the (up to) 10 most recent commands entered from the user. See details below how this should work.
r n
The r n internal shell command will execute a command from the history list. See details below how this should work.
I/O Redirection: Your shell must support I/O redirection. By default, guish runs programs so that input data is read from standard input and output data is written to standard output. However, this behavior can be changed using I/O redirection. I/O redirection is specified using the <, > operators. For example:
progname [args] > file.out
Write the standard output of progname to the file file.out.
progname [args] < file.in
Uses the contents of the file file.in as the standard input to program progname.
Both input and output redirection may be specified for a single command so your shell will have to check for both and operate accordingly. The redirections can be specified in any order.
Handling Erroneous Programs: Finally, when programs terminate, they return an integer exit code to your shell. If this code is non-zero, your shell should print the returned value. For example
guish: cp foo bar
cp: cannot access foo
[ Program returned exit code 1 ]
guish:
Getting Started
Make sure you understand the assignment before beginning any work. Now, a guish shell template, parser, and makefile are provided for you.
The name of our shell will be called New Island Shell (guish). You are provided with the files guish.l and guish.cpp which contain some source code that uses gettoks(), a function provided by guish.l to get and parse a line of input. The function gettoks() returns an array of pointers to character strings (i.e. NULL terminated C style strings). Each string is either a word containing the letters, numbers, ., and /, or a single character string containing one of the special characters: ( ) < > | & ;.
To compile guish.l, you have to use flex: "flex guish.l". This will produce a file called (by default) lex.yy.c which is compiled with gcc. The file guish.cpp will be compiled with g++. The final step is to link the object files lex.yy.o and guish.o with the flex library -lfl. If this is all confusing, here is a Makefile to simplify the entire process. (with a few modifications)
Other Shell Details
Your shell must support the following:
The command exit is an internal shell command. It will cause your shell program to quit and print the interrupt counts.
The ONLY way your program is to exit is via the 'exit' command at the prompt. Therefore your shell will have to trap the appropriate signals. When your shell 'exits' display a list of the signals your shell traps and the number of interrupts of each type. (Ctrl C, Ctrl \, Ctrl Z)
The internal shell command "hist" which displays (up to) the ten most recent commands typed into your shell. The hist command will be added to the history. The commands will always be numbered from 1 to 10.
All commands (internal or external, successful or unsuccessful, except r and exit) are added to the history list.
The internal shell command "r n" where 'n' is the history number of that command in the history list. Also, the user should be able to run the most recent command again by just entering 'r'. You can assume that one space will separate the the 'r' and the number of the command. Any command that is executed in this fashion should be echoed on the user's screen and the command is also placed in the history buffer as the next command. The r command is not added to the history list but the referenced command is added to the history list.
Take some creative liberty is designing your shell prompt. You could include the name of the shell, current working subdirectory, command number, etc. Static prompts will result in loss of points.
You must check and correctly handle all return values. This means that you need to read the man pages for each function to understand what the possible return values are, what errors they indicate, and what you must do when you get that error.
You may not use the "system()" system function in your shell. However, this function call is good for prototyping and debugging.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started