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, 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 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.
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.
Why Work with Us
Top Quality and Well-Researched Papers
We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.
Professional and Experienced Academic Writers
We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.
Free Unlimited Revisions
If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.
Prompt Delivery and 100% Money-Back-Guarantee
All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.
Original & Confidential
We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.
24/7 Customer Support
Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.
Try it now!
How it works?
Follow these simple steps to get your paper done
Place your order
Fill in the order form and provide all details of your assignment.
Proceed with the payment
Choose the payment system that suits you most.
Receive the final file
Once your paper is ready, we will email it to you.
No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.
No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.
Admission Essays & Business Writing Help
An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.
Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.
If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.