Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

MongoDB Applied Design Patterns Practical Use Cases With The Leading NoSQL Database

Authors: Rick Copeland

1st Edition

1449340040, 978-1449340049

More Books

Students also viewed these Databases questions

Question

Describe the five elements of the listening process.

Answered: 1 week ago