Question: 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

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;

For your first Homework, you will code a simple program in C++ 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

Which would substitute lpr for the first argument followed by -Plj1026 for the second argument. Your shell should fork and execute the command in a separate process. It should then wait for the command to be done 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.

In this question, you will NOT be doing wildcard substitution, redirection, piping, or actually use the history

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.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!