Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is a fun project that brings together many concepts already presented in class. Enjoy this project and have fun! Objective The purpose of this

This is a fun project that brings together many concepts already presented in class. Enjoy this project and have fun!
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/Linux environment. In this assignment you are to implement a UNIX/Linux 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]
Example:
char * argv[4]={"ls","-l","-a", NULL};
execvp(argv[0], argv);
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.
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:
In case the program doesn't exist. In the child process: cout << "The program seems missing. Erro code is: "<< errno << endl;
In case the program returns error. In the parent process: cout << "The program existed with error: "<< status << endl;;
Getting Started
Make sure you understand the assignment before beginning any work..
The name of our shell will be called New Shell (guish)..
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.
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.
Getting Help
You are expected to do your own work and research regarding the usage of various system calls, header files, and libraries. Information is readily available in the man pages, UNIX reference books, or on the web. Otherwise, do not hesitate to ask a question if you are unclear about how some part of the assignment is supposed to work.
#include
#include
#include
#include
#include
#include
#include

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions