Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For your first Homework, you will write a simple program to read commands from the console and execute them. The mini shell should look for

For your first Homework, you will write a simple program to read commands from the console and execute them. The mini shell should look for commands in the current path to execute and, if they are present, execute them. If the command is not found an error message stating command not found should be sent to cerr or stderr. Rather than just executing commands as typed you will have an alias facility. The alias facility will allow the user to customize commands. For example, if they would prefer dir rather than ls they would type

alias dir ls

And then when they type dir your program will substitute in ls (for the first argument only). The alias facility can also include multiple words or flags and they can be substituted. Another example would be:

alias print lpr -Plj1026 "Print results in two arguments substituted lpr and Plj1026 No, you cant alias an alias"

Which would substitute lpr for the first argument followed by -Plj1026 for the second argument. "If you said alias p print It shouldnt check on print being an alias and substitute in the lpr Plj1026 command"

Your shell should fork and execute the command in a separate process.(You are NOT allowed to use the system call. Must be fork/exec/wait) It should then wait for the command to finish and print out the status code for the job along with the resource usages (see wait3 and wait4 calls). Lastly, your shell should keep a list of the commands that have been run (a history) and at the end of the shell session it should be saved in a file named .minihistory. (Command after alias substitutions should be saved.)*

In this assignment you will NOT be doing wildcard substitution, redirection, piping, or actually use the history. We may choose to do that later.

Structs

Structures are what was in C prior to C++. They group together fields into a single variable.

There are no methods with a struct

There are no access types with a struct (private, public, protected)

Everything is public they are just there to allow easy grouping of data.

Accessed the same way an object would be: struct rusage r; cout << r.ru_maxrss;

Approach

I would suggest starting without worrying about alias commands.

I would simply try to fork/execute/wait on a command typed in by the user and see if that works first. Then the other details could be added in.

Need to split the command into pieces white space should be used to do this.

Do not need to worry about escape characters or quotes.

Execlp and execvp work with paths. It would be the easier to use one of them.

*History

Should the aliasing be saved to the history so it can be brought back in as well

Yes, save it to history.

The history will eventually allow us to move back to commands from a previous session. When we start up the shell a second time the old aliases do not get applied unless the user goes back and executes those commands.

If you want to make an alias that happens every time you would normally use a .cshrc, .shrc, .bashrc, .tcshrc file with those commands in it.

Please explain what info you need i posted everything i have

Then how can I post more info

then stop request more information either answer or let someone else answer it.

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

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students also viewed these Databases questions

Question

i need correct answrrs 2 4 2 . .

Answered: 1 week ago

Question

What is the environment we are trying to create?

Answered: 1 week ago

Question

How can we visually describe our goals?

Answered: 1 week ago