Question: Edit the code (shell.c) given to do the tasks asked! will rate for correct answer! Also, include a screen shot of the output and terminal

Edit the code (shell.c) given to do the tasks asked! will rate for correct answer! Also, include a screen shot of the output and terminal window of each command you used. Read carefully to do this task please. Edit the code (shell.c) given to do the tasks asked! will rate for correct answer! Also, include a screen shot of the output andshell.c code given below.

#include  #include  #include  #include  #include  int main() { int PID; char lineGot[256]; char *cmd; while (1){ printf("cmd: "); fgets(lineGot, 256, stdin); // Get a string from user (includes ) cmd = strtok(lineGot, " "); // Get the string without the if( strcmp(cmd, "e") == 0 ) // loop terminates when "e" is typed exit (0); // creates a new process. Parent gets the child's process ID. Child gets 0. if ( (PID=fork()) > 0) { wait(NULL); } else if (PID == 0) /* child process */ { execlp (cmd, cmd, NULL); /* exec cannot return. If so do the following */ fprintf (stderr, "Cannot execute %s ", cmd); exit(1); /* exec failed */ } else if ( PID == -1) { fprintf (stderr, "Cannot create a new process "); exit (2); } } }

Task 1 (100 points) There are many variations of the exec system call that can be used to execute an executable file (program) Calling exec does not create a new process, it replaces the current process with the new process. If the exec command fails, then it returns -1. But if it succeeds it does not return because execution proceeds at the beginning of the program that was execut ed. We will consider some useful forms of exec commands. 1. execl: takes the path name of an executable as its first argument, the rest of the arguments are the command line arguments ending with a NULL. execl("/bin/ls", "1s", "-a", "-l", NULL) 2. execv: takes the path name of a binary executable as its first argument, and a NULL terminated array of arguments as its second argument. The first element can be the command or" ". static char* args("Is", "-a", "-1", NULL; execv("/bin/1s", args) 3. execlp: same as execl except that we don't have to give the full path name of the command execlp ( " ls " , " ls " , "-a" , "-I " , NUTIL) ; 4. execvp: Same as exexv except that we don't have to give the full path name of the command static char * args[ execvp ("ls" ] = {"ls", "-a", "-1", NULI.); , args)

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!