Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please complete the following things: 1. parse and interpret input to the shell 2. create and wait on child processes 3. handle I/O input and

image text in transcribed

image text in transcribed

Please complete the following things:

1. parse and interpret input to the shell

2. create and wait on child processes

3. handle I/O input and output redirection, and

4. implement shell internal commands.

Objective Implement a simple shell or command line interpreter Problem Description The Shell or Command Line Interpreter is the fundamental user interface provided by an operating system. Implement a simple shell called blazersh that provides the following functionality: 1. When the shell is invoked by executing the executable blazersh, it should provide a prompt blazersh> and waits for any input from the keyboard. 2. Any input entered will be interpreted as a program to be executed and the shell should create a new process corresponding to the input entered using fork/exec. You can assume that the newline character denotes the end of the input. If a newline character is entered without any other text or followed by white space, the shell should just display the prompt on the next line. The new process created should be able to read keyboard input and display output to the terminal. You can assume that these programs are executed only in the foreground, i.e., the shell program will wait for the child process to complete and when the child process completes successfully it will display the command prompt. Here is a sample interaction with the shell (assuming myprog1 and myprog2 are in one of the directories defined by the PATH environment variable) blazersh> myprog1 Hello World! blazersh> myprog2 5 The 5 values createdd are: 10 11 12 13 14 blazersh> blazersh> myprog2 Enter the number of elements: 5 The 5 values created ar: 10 11 12 13 14 blazersh> 3. The shell program should also support I/O redirection for both standard input and standard output. For example, the command below should execute the program myprogram with command-line arguments arg1 and arg2, use inputfile file for standard input file stream and send standard output file stream to the file outputfile. If the file outputfile does not exist, a new file should be created and if the file outputfile exists, it should be over-written. You can assume that whitespace will serve as the delimiter for the I/O redirection symbols . blazersh> myprogram argi arg2 inputfile > outputfile blazersh> myprogram argi arg2 inputfile > outputfile Page 1 of3 CS 433/533 Operating Systems Homework-1 4. In addition to creating a new process corresponding to each command entered, the shell should also support the following internal commands: environ - list all environment strings as name-value. T all the environment variables that were defined (in the bash shell) when the shell program was invoked a. The shell program should inherit b. set - should set the environment variable the value specified by and add this to the environment strings if this is a new variable that was not defined earlier list - list all the files in the current directory. The default directory is the directory where the shell program was invoked or the directory specified by the PWD environment variable cd and waits for any input from the keyboard. 2. Any input entered will be interpreted as a program to be executed and the shell should create a new process corresponding to the input entered using fork/exec. You can assume that the newline character denotes the end of the input. If a newline character is entered without any other text or followed by white space, the shell should just display the prompt on the next line. The new process created should be able to read keyboard input and display output to the terminal. You can assume that these programs are executed only in the foreground, i.e., the shell program will wait for the child process to complete and when the child process completes successfully it will display the command prompt. Here is a sample interaction with the shell (assuming myprog1 and myprog2 are in one of the directories defined by the PATH environment variable) blazersh> myprog1 Hello World! blazersh> myprog2 5 The 5 values createdd are: 10 11 12 13 14 blazersh> blazersh> myprog2 Enter the number of elements: 5 The 5 values created ar: 10 11 12 13 14 blazersh> 3. The shell program should also support I/O redirection for both standard input and standard output. For example, the command below should execute the program myprogram with command-line arguments arg1 and arg2, use inputfile file for standard input file stream and send standard output file stream to the file outputfile. If the file outputfile does not exist, a new file should be created and if the file outputfile exists, it should be over-written. You can assume that whitespace will serve as the delimiter for the I/O redirection symbols . blazersh> myprogram argi arg2 inputfile > outputfile blazersh> myprogram argi arg2 inputfile > outputfile Page 1 of3 CS 433/533 Operating Systems Homework-1 4. In addition to creating a new process corresponding to each command entered, the shell should also support the following internal commands: environ - list all environment strings as name-value. T all the environment variables that were defined (in the bash shell) when the shell program was invoked a. The shell program should inherit b. set - should set the environment variable the value specified by and add this to the environment strings if this is a new variable that was not defined earlier list - list all the files in the current directory. The default directory is the directory where the shell program was invoked or the directory specified by the PWD environment variable cd

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_2

Step: 3

blur-text-image_3

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

Oracle Databases On The Web Learn To Create Web Pages That Interface With Database Engines

Authors: Robert Papaj, Donald Burleson

11th Edition

1576100995, 978-1576100998

More Books

Students also viewed these Databases questions