19 Jul Shell built-in commands, unlike legacy executables such as /bin/ls or /usr/bin/vim, are internal features of
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.
HOW OUR WEBSITE WORKS
Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of
HIGH QUALITY & PLAGIARISM FREE.
To make an Order you only need to click ORDER NOW and we will direct you to our Order Page at WriteDen. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Deadline range from 6 hours to 30 days.
Once done with writing your paper we will upload it to your account on our website and also forward a copy to your email.
Upon receiving your paper, review it and if any changes are needed contact us immediately. We offer unlimited revisions at no extra cost.
Is it Safe to use our services?
We never resell papers on this site. Meaning after your purchase you will get an original copy of your assignment and you have all the rights to use the paper.
Our price ranges from $8-$14 per page. If you are short of Budget, contact our Live Support for a Discount Code. All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.
Please note we do not have prewritten answers. We need some time to prepare a perfect essay for you.