Question: OVERVIEW In this assignment, you will create a Unix shell that runs a series of basic commands. The program should run as follows: when a

OVERVIEW
In this assignment, you will create a Unix shell that runs a series of basic commands. The
program should run as follows: when a user enters a command, a child process will be created
that will then execute the command. After the command is executed, the program should prompt
the user for more inputs. When writing this program, you will need to use the system calls fork(),
execvp(), and wait)
DETAILS
The program will begin by prompting the user to enter input, as with any shell. For example,
upon running the program, the user should see:
S>>
The user should be able to then type any command (cat file.cpp, ls -1, etc) and the program
should then run that command and upon finishing, prompt the user to enter another input.
The program should be able to run any normal command that you can run in a terminal,
however, I will only be looking for the above two commands ("cat file.cpp" and "ls -l"). Do not
hard code these inputs.
The user should be able to continuously enter in inputs unless "exit" is entered, which will then
close the program. If the user enters a command that is unknown, "unknown command" will be
shown to the user and they will be prompted to enter another input (S>>).
Your assignment will require two functions: the main function, as well as a "parse" function that
will parse the user's input. Do not parse the input in the main function.
CODE OUTLINE
Below is an outline for the code that you will need to write to complete this assignment.
#include < stdio.h>
#include
#define MAX LINE 80/* The maximum length command */
Int main(void)
{
Char*args[MAX LINE/2+1]; /* command line arguments */
Int should run =1; /* flag to determine when to exit program */
While (should run){
Printf(osh>);
*Call parse function
Fflush(stdout);
/**
*After reading user input, the steps are:
*(1) fork a child using fork()
*(2) the child process will invoke execvp()
*(3) parent will invoke wait()
*/
}
Return 0;
}
** THIS CODE IS FROM THE BOOK AND IS ONLY TO GIVE YOU AN OUTLINE. IT
DOESN'T RUN. YOU DO NOT NEED TO USE THIS CODE.
You will need to look up the system calls fork() and execvp() and understand what parameters
they require. The user's input should be parsed so that each command has its own index in the
args array.
For example, if the user enters "ls -l" the args array should look like so:
args[0]=1s
args[1]=-1
args[2]=/NU LL
You will then pass this array in the parameters of the execvp() function. If the user's input is
parsed correctly (like above) you will simply need to call the execvp function like so:
execvp(args[0],args)
UNKNOWN INPUTS
The program you are creating should display "unknown command" when the user enters
something that is not a command ("uiuiui"). As stated above, the child process should call the
execvp() function. If this function returns, it indicates there has been an error.
With this in mind, your code to display error messages should be underneath the execvp()
function.

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 Accounting Questions!