Question: A CLI accepts textual input from the user, and executes the commands issued. The main logic of the CLI is given below: main: loop get

A CLI accepts textual input from the user, and executes the commands issued. The main logic of the CLI is given below:

main: loop

get input line

if end of input exit

break line into words

found := false

if command is builtin

then

do_builtin(line)

found:=true

else

found:=find_and_execute(line)

end if

if not found report error

end loop

Write a program that repeatedly reads a line of input from the user, the fgets() function will help you here. Your program should end when either end of the input file is encountered, or the exact word exit appears in the input as the only word on a line. Traditionally both the File System and Command Language are case sensitive, you should also implement this.

Break the line up into words, which are separated by one or more spaces. The provided function tokenize() does this, and it uses strtok() internally. You may use this function if you wish, in which case you should provide documentation on its operation, or you may write your own parser.

Implement the find_and_execute() section of the logic above, by creating a new process using fork(), and then use one of the exec() family of functions to run the program requested by the user in the text provided. If the requested program cannot be run then an appropriate error message should be displayed, perror() will help with this (as there are many reasons why this may fail), and the child process terminated.

Step by Step Solution

3.45 Rating (155 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Heres the C code for a simple CLI that implements the specified logic include include include includ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Operating System Questions!