Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have posted the code on slide 64 twice now, I don't understand what else it is you need me to do to clarify it

I have posted the code on slide 64 twice now, I don't understand what else it is you need me to do to clarify it more

4. Extended CLI: Extend the CLI example discussed in class (slide 64 in Ch_03_a.pdf) so it is not limited to only the list of possible commands. The new program should loop through the following:

1. Prompt to the user and wait for their input.

2. Read the user input, tokenize it and build a NULL-terminated string array.

3. Create a new process to execute the user command

4. Parent process should wait until user command is executed before it returns to step 1

Here is the CLI code from slide 64 chapter 3 in C:

main() {

char *cmd[]={who , ls , date};

int i;

while(1){

printf(0=who, 1=ls, 2=date :) ;

scanf(%d, &i);

if (fork() == 0) {

execlp(cmd[i], cmd[i],0);

printf(command not found );

/*exec failed*/

exit(1);

} //if

else

wait(0);

} //while

} //main

image text in transcribed

main () I char *cmd [ ] = { "who,, , "ls" , "date" } ; int i; while (1)( printf ("O-who, 1-ls, 2-date scanf ("8d", &i); execlp (cmd[i], cmd[i], 0) printf("command not found ") ; /*exec failed*/ exit(1); > //if else wait (0); } //while } //main

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

13th Edition Global Edition

1292263350, 978-1292263359

More Books

Students also viewed these Databases questions

Question

What are their reputations?

Answered: 1 week ago

Question

=+2 Why did OBI create Centers of Excellence?

Answered: 1 week ago

Question

=+professionalism and competency in handling global HR issues?

Answered: 1 week ago