subject

In this assignment, you will implement a command line interpreter (CLI) or, as it is more commonly known, a shell. The shell should operate in this basic way: when you type in a command (in response to its prompt), the shell creates a child process that executes the command you entered and then prompts for more user input when it has finished. The shells you implement will be similar to, but simpler than, the one you run every day in Unix. If you don't know what shell you are running, try the command ‘echo $SHELL’. One thing you should do on your own time is learn more about your shell, by reading the man pages or other online materials. Program Specifications Basic Shell: dash Your basic shell, called dash (short for DAllas SHell), is basically an interactive loop: it repeatedly prints a prompt dash> (note the space after the greater-than sign), parses the input, executes the command specified on that line of input, and waits for the command to finish. This is repeated until the user types exit. The name of your final executable should be dash. The shell can be invoked with either no arguments or a single argument; anything else is an error. Here is the no-argument way:
prompt> ./dash
dash>
At this point, dash is running, and ready to accept commands. Type away! The mode above is called interactive mode, and allows the user to type commands directly. The shell also supports a batch mode, which instead reads input from a batch file and executes commands from therein. Here is how you run the shell with a batch file
named batch. txt:
prompt> ./dash batch. txt
One difference between batch and interactive modes: in interactive mode, a prompt is printed (dash>). In batch mode, no prompt should be printed. You should structure your shell such that it creates a process for each new command (the exception are built-in commands, discussed below). Your basic shell should be able to parse a command and run the program corresponding to the command. For example, if the user types ls -la /tmp, your shell should run the program /bin/ls with the given arguments -la and /tmp (how does the shell know to run /bin/ls? It's something called the shell path; more on this below).
Structure
Basic Shell
The shell is very simple (conceptually): it runs in a while loop, repeatedly asking for input to tell it what command to execute. It then executes that command. The loop continues indefinitely, until the user types the built-in command exit, at which point it exits. That's it!
For reading lines of input, you should use getline(). This allows you to obtain arbitrarily long input lines with ease. Generally, the shell will be run in interactive mode, where the user types a command (one at a time) and the shell acts on it. However, your shell will also support batch mode, in which the shell is given an input file of commands; in this case, the shell should not read user input (from stdin) but rather from this file to get the commands to execute.
In either mode, if you hit the end-of-file marker (EOF), you should call exit(0) and exit gracefully.
To parse the input line into constituent pieces, you might want to use strtok() (or, if doing nested tokenization, use strtok_r()). Read the man page (carefully) for more details. To execute commands, look into fork(), exec(), and wait()/waitpid().
See the man pages for these functions, and also read the relevant book chapter for a brief overview. You will note that there are a variety of commands in the exec family; for this project, you must use execv. You should not use the system() library function call to run a command. Remember that if execv() is successful, it will not return; if it does return, there was an error (e. g., the command does not exist). The most challenging part is getting the arguments correctly specified.
Paths
In our example above, the user typed ls but the shell knew to execute the program /bin/ls. How does your shell know this?

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 18:40
Mariah was working on a multimedia presentation that included both video and audio files. the file was huge, and she wanted to send it to her coworker in another office. she needed to reduce the size of the file so that it could be transmitted faster. the utility she used to do this was
Answers: 2
question
Computers and Technology, 22.06.2019 19:30
Singing in the rain: this first part of the film shows the early history of motion picture. how accurate do you think the portrayal of the early motion picture industry is? why? is historical accuracy important in films and theater productions? explain.
Answers: 1
question
Computers and Technology, 23.06.2019 01:50
Create a class named majors that includes an enumeration for the six majors offered by a college as follows: acc, chem, cis, eng, his, phys. display the enumeration values for the user, then prompt the user to enter a major. display the college division in which the major falls. acc and cis are in the business division, chem and phys are in the science division, and eng and his are in the humanities division. save the file as majors.java.
Answers: 2
question
Computers and Technology, 23.06.2019 03:30
Hashtags serve to identify the topic of a given tweet true false
Answers: 2
You know the right answer?
In this assignment, you will implement a command line interpreter (CLI) or, as it is more commonly k...
Questions
question
Mathematics, 18.02.2021 17:10
question
Mathematics, 18.02.2021 17:10
question
English, 18.02.2021 17:10
question
Mathematics, 18.02.2021 17:10
question
Biology, 18.02.2021 17:10
question
Mathematics, 18.02.2021 17:10
Questions on the website: 13722361