Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

VAssignment 1 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 #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 process using fork() * (2) the child process will invoke execvp0 * (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 execup() 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 "Is -1 the args array should look like so: args[0] =ls args[1]="-1" args[2] =NULL" You will then pass this array in the parameters of the execup() 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. GRADING 50 points - user's input is parsed into the args array correctly 30 points - child process invokes execvp() system call, parent invokes wait() system call 20 points - if the user enters exit, the program is terminated. If the user enters an unknown command, "unknown command" is shown to the user and they are prompted to enter another input. VAssignment 1 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 #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 process using fork() * (2) the child process will invoke execvp0 * (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 execup() 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 "Is -1 the args array should look like so: args[0] =ls args[1]="-1" args[2] =NULL" You will then pass this array in the parameters of the execup() 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. GRADING 50 points - user's input is parsed into the args array correctly 30 points - child process invokes execvp() system call, parent invokes wait() system call 20 points - if the user enters exit, the program is terminated. If the user enters an unknown command, "unknown command" is shown to the user and they are prompted to enter another input

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

Database Design And Implementation

Authors: Edward Sciore

2nd Edition

3030338355, 978-3030338350

More Books

Students also viewed these Databases questions

Question

For the standard normal density (x), show that 0(x) x(x).

Answered: 1 week ago

Question

What is meant by organisational theory ?

Answered: 1 week ago

Question

What is meant by decentralisation of authority ?

Answered: 1 week ago

Question

Briefly explain the qualities of an able supervisor

Answered: 1 week ago

Question

Define policy making?

Answered: 1 week ago

Question

Define co-ordination?

Answered: 1 week ago

Question

2. Develop a persuasive topic and thesis

Answered: 1 week ago

Question

1. Define the goals of persuasive speaking

Answered: 1 week ago