Reference no: EM132213972
Write a small C program called tinyshell that behaves much like a shell; but your program has to accept and respond to the following four commands only, presented one at a time:
world n - run the command called world and pass the argument n to it
mars n - run the command called mars and pass the argument n to it
newcat file - run the newcat program to display the file on standard output
quit - terminate execution of the tinyshell
The tinyshell program works as follows: puts out a prompt next command> and then reads the command string typed by the user (use scanf).
If the command typed by the user is not one of the above four, it responds with an error message and prompts the user again. If the command typed is quit the program is terminated.
Otherwise, it reads, as a string, the remaining part of the command (i.e., the count n or the file name). Then it executes the command world or mars or newcat as required.
For this, tinyshell forks and the parent process immediately executes wait. The child process executes execlp to overlay itself with the code of world or mars or newcat. On its completion, the parent process resumes execution putting out a new prompt for the next command.