Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write your own simple shell. Your shell should prompt the user for a command, run it, then prompt the user for their next command. If

Write your own simple shell. Your shell should prompt the user for a command, run it, then prompt the user for their next command. If the user types "exit", then the shell should terminate. The shell should ignore Ctrl-C.

Inside the attached parse.h header file (at the bottom), there is a parse function that you can use to split up the command line into separate strings. Recall that execvp accepts two arguments: the name of the command, and then an array of command-line arguments as strings. The parse() function in parse.h accepts the string and returns the array of argument strings.

You can use parse.h or roll your own parse function.

Hints :

Remember the logic for the shell :

while input != exit parse the command fork if parent process : wait else execvp command

You'll need the chdir system call to add support for cd. This needs to be part of the shell as their is no cd system command.

man chdir, execvp, wait, fork, strtok

This may be the most challenging assignment of the quarter for some people. Don't wait to get started on it.

Parse.h :

// splits input into separate strings // inputs: input: a string to split up, args: an array of char pointers to // store the separate strings // outputs: an array of strings, with null in the last element, passed back // through args // preconditon: input is a valid c-string, read from the keyboard using fgets // postcondition: args contains the separate strings, one // string per element. Last element contains null #ifndef PARSE_H #define PARSE_H #include "string.h" static void parse( char* input, char* args[] ) { int i = 0; // fgets reads the , so overwrite it input[strlen(input)-1] = '\0'; // get the first token args[i] = strtok( input, " " ); // get the rest of them while( ( args[++i] = strtok(NULL, " ") ) ); } #endif 

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

Upgrading Oracle Databases Oracle Database New Features

Authors: Charles Kim, Gary Gordhamer, Sean Scott

1st Edition

B0BL12WFP6, 979-8359657501

More Books

Students also viewed these Databases questions

Question

Apply Min - Max Alpha - Beta pruning

Answered: 1 week ago

Question

Azure Analytics is a suite made up of which three tools?

Answered: 1 week ago

Question

How was your life influenced by those events?

Answered: 1 week ago

Question

Which of these influenced your life most dramatically?

Answered: 1 week ago