Question
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
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 } //mainStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started