Question
Help in UNIX bash Modify simple-sh.c program to write simple-sh1.c program (in a loop) - (a) to accept a command-string (e.g., ls), (b) to fork
Help in UNIX bash
Modify simple-sh.c program to write simple-sh1.c program (in a loop) - (a) to accept a command-string (e.g., ls), (b) to fork a child process to handle the command by calling execlp where this part will replace the system call, (c) while the parent is waiting for the child to complete and then to resume the loop to accept the next command.
#include
int main() { char line[256]; char prompt[] = "SimpleShell: Enter command or exit % ";
/* spit out the prompt */ printf("%s", prompt );
/* Try getting input. If error or EOF, exit */ while( fgets(line, sizeof line, stdin) != NULL ) { /* fgets leaves ' ' in input buffer. ditch it */ line[strlen(line)-1] = '\0';
if(strcmp(line,"exit") == 0){ break; } else { system( line ); }
printf("%s", prompt ); }
return 0; }
Step 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