Question: 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

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.

/* * sh1.c: sample version 1 of a UNIX command shell/interpreter. * */

#include #include #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

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!