In: Computer Science
Using Virtualbox in Debian, write a simple program (a single .cpp file) in Linux shell C++
Rules:
-Use fork(), exec(), wait(), and exit()
_______________________________________________________________________________________________________________________________________________
-A line of input represents a token group.
-Each token group will result in the shell forking a new process and then executing the process.
e.g. cat –n myfile.txt // a token group
-Every token group must begin with a word that is called the command(see example above). The words immediately following a command are calledarguments(e.g. there are two arguments for the catcommand above).A command may be followed bynone, one, or more argumentsas the command allows to have.
_______________________________________________________________________________________________________________________________________________
Shell Commands:
ls: a token group containing one token(i.e.a command)
ls -l: a token group containing two tokens (i.e.a command and an argument)
sort infile: a tokengroup containingtwo tokens (i.e.acommand and an argument)
dir: a token group containingonly one token (i.e.a command)
sort –dinfile: atoken group containingthree tokens (i.e.a command and two arguments)
cat infile: a token group containing two tokens (i.e.a command and an argument)
Lines of input are interpreted once their tokens are correctly extracted.Your shell should first print a # sign to the screen representing a prompt and wait there until the user types in a command. Your shell then spawns a child process to carry out the command.When yourshell finishes processingthe current line, it prints a # sign again to the screen waiting for the user to type in another command.This process is repeated until the user presses Ctrl-C to terminate your shell.
-Every command is to be interpreted as a valid Linux executable to be executed.
-All commands are assumed to be in the current directory.
-After interpreting a command, the shell should wait for the forked processto terminate before processingthe next line of input.
The program should be able to extract tokens from each input line entered by the user. If you have problems with extracting tokens from input lines, you may use the C++ library function strtok() to do it.