C program, shell build in command

Shell built-in commands, unlike legacy executables such as /bin/ls or /usr/bin/vim, are internal features of a shell that the user may invoke. For example, alias (to create a shortcut such as ‘l’ for ‘ls’), cd, history are among common built-in commands supported by most shells. When a user enters a command, a shell must first check if it is a built-in command in which case forking a child to load and run a legacy executable is not required. If the entered command is not built-in, then a shell assumes that it is a binary executable that needs to found and executed by a worker process. Extending built-in commands into a programming language, called shell scripts, is a popular way to manage and automate tasks on UNIX based operating systems such as Linux and MacOS.

Use the code of main4.c as a starting point to extend its capability to support the following built-in commands:

$ cprompt <x>

where <x> is 0, 1, 2 or 3. The notation <x> means that x is a variable. When <x> is 0, the default prompt ‘$’ is output. If <x> is 1, the prompt is changed to ‘>’. <x> equals to 2 changes the prompt to the PID of the process. Implement your own prompt for the case where <x> equals 3. Annotate your code to describe what option 3 outputs.

$ mem <s>

where <s> is a string that is stored in a memo note. Implement the memo note as a 1-D array of maximum size 10, char *memnote[10], where each element is a pointer to a string. Use malloc() to allocate just enough memory to store the string <s>. When memnote[] is full, cycle to the beginning and overwrite memnote[0] with the new string. Hence memnote[] is a circular array that overwrites the oldest element if space is full. Keep track of the newest and oldest memo note so that when the user enters the command ‘mem’ without a string <s> then the memo note strings are output by recency, with the newest first and the oldest last, by the order the user has added them to the memnote string array.

$ d <sec> <binexec>

The command d asks that the shell delay running the legacy executable <binexec> by <sec> seconds. Perform this task by calling library function sleep() with <sec> as argument. Look up section 3 of the man pages (run % man 3 sleep) to check how to use sleep() including any header files. First fork a child process who checks if a delay is needed by inspecting a variable, int delayflag, set by the parent. If 1, sleep() is called with argument <sec> followed by execlp() of <binexec>. Otherwise, execlp() is called without delay. In the case delayed execution is requested by the user, the parent does not call waitpid() to wait until the child terminates. Instead, it returns to the beginning of the while loop to print a fresh prompt since the delay could be substantial.

$ x

The command x without arguments means to terminate the shell. The shell prints a suitable message to stdout, then calls exit(0) to terminate.

Although main4.c serves as the main skeleton code, implement the built-in features supported by the shell, call it mysh, in a modular fashion making calls to functions that are put in their own file in a folder v12. Create a README text file that describes what each file in a folder v12 contains and its role. Use a Makefile to compile your code. 20 points out of 150 will be assigned for modularity, clarity, and style. Although not necessary, you may use string processing library functions. The library function atoi() which converts a number represented as a string (e.g., “3075”) into an integer (3075) may be useful. Look up its man page if you decide to use it. Test and verify that mysh works correctly. the code should run under Mac terminal. 

Calculate Your Essay Price
(550 words)

Approximate price: $22

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more