Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am confused on how to even start working on this shell or even coding a command line for the user to provide input for

I am confused on how to even start working on this shell or even coding a command line for the user to provide input for the machine to read. Could anyone please help me get a start to do this? I don't care if you don't completely flesh out the code with the commands specified below, I would just appreciate having a direction I can follow. Thank you!!

I would prefer the code to be written in C aswell please.

image text in transcribed

Specifications The Prompt Use the colon : symbol as a prompt for each command line. Be sure you flush out the output buffers each time you print, as the text that you're outputting may not reach the screen until you do in this kind of interactive program. To do this, call fflush() immediately after each and every time you output text. The general syntax of a command line is: command (argi arg2 ...] [output_file] [&] ...where items in square brackets are optional. You can assume that a command is made up of words separated by spaces. The special symbols , and & are recognized, but they must be surrounded by spaces like other words. If the command is to be executed in the background, the last word must be &. If the & character appears anywhere else, just treat it as normal text. If standard input or output is to be redirected, the > or junk, then you handle the redirection to "junk" with dup2() and then simply pass is into exec()). Note that exec() will fail, and return the reason why, if it is told to execute something that it cannot do, like run a program that doesn't exist. In this case, your shell should indicate to the user that a command could not be executed (which you know because exec() returned an error), and set the value retrieved by the built-in status command to 1. Make sure that the child process that has had an exec() call fail terminates itself, or else it often loops back up to the top and tries to become a parent shell. This is easy to spot: if the output of the grading script seems to be repeating itself, then you've likely got a child process that didn't terminate after a failed exec(). Your shell should use the PATH variable to look for non-built in commands, and it should allow shell scripts to be executed. If a command fails because the shell could not find the command to run, then the shell will print an error message and set the exit status to 1. As above, after the fork() but before the exec() you must do any input and/or output redirection with dup20). An input file redirected via stdin should be opened for reading only, if your shell cannot open the file for reading, it should print an error message and set the exit status to 1 (but don't exit the shell). Similarly, an output file redirected via stdout should be opened for writing only; it should be truncated if it already exists or created if it does not exist. If your shell cannot open the output file it should print an error message and set the exit status to 1 (but don't exit the shell). Both stdin and stdout for a command can be redirected at the same time (see example below). Your program must expand any instance of "$$" in a command into the process ID of the shell itself. Your shell does not otherwise perform variable expansion. This feature makes it easier to create a grading script that keeps your work separate

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

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

Students also viewed these Databases questions

Question

=+8.3(i)). If j is transient, then fi= C PH) /(1+2 Pc)

Answered: 1 week ago