Question: ush1.c: #include #include #include #include #define MAX_BUFFER 256 #define QUIT_STRING q int makeargv(const char *s, const char *delimiters, char ***argvp); int main (void) { char

 ush1.c: #include #include #include #include #define MAX_BUFFER 256 #define QUIT_STRING "q"

ush1.c:

#include  #include  #include  #include  #define MAX_BUFFER 256 #define QUIT_STRING "q" int makeargv(const char *s, const char *delimiters, char ***argvp); int main (void) { char **chargv; char inbuf[MAX_BUFFER]; for( ; ; ) { gets(inbuf); if (strcmp(inbuf, QUIT_STRING) == 0) return 0; if ((fork() == 0) && (makeargv(inbuf, " ", &chargv) > 0)) execvp(chargv[0], chargv); wait(NULL); } }

makeargv.c:

#include  #include  #include  int makeargv(const char *s, const char *delimiters, char ***argvp) { int error; int i; int numtokens; const char *snew; char *t; if ((s == NULL) || (delimiters == NULL) || (argvp == NULL)) { errno = EINVAL; return -1; } *argvp = NULL; snew = s + strspn(s, delimiters); /* snew is real start of string */ if ((t = malloc(strlen(snew) + 1)) == NULL) return -1; strcpy(t, snew); numtokens = 0; if (strtok(t, delimiters) != NULL) /* count the number of tokens in s */ for (numtokens = 1; strtok(NULL, delimiters) != NULL; numtokens++) ; /* create argument array for ptrs to the tokens */ if ((*argvp = malloc((numtokens + 1)*sizeof(char *))) == NULL) { error = errno; free(t); errno = error; return -1; } /* insert pointers to tokens into the argument array */ if (numtokens == 0) free(t); else { strcpy(t, snew); **argvp = strtok(t, delimiters); for (i = 1; i   Consider the code shown in htp://usp.cs.utsa.edu/usp/programs/chapterl1/ushl.c a) How would the shell implemented in ush1.c behave when the user gives an invalid command (i.e. a command for which no executable exists)? (5 points) b) What would happen if the user gives multiple invalid commands? (5 points) c) What happens when the user tries to quit the shell after giving multiple invalid commands. (5 points) You can assume that the makeargv0 function (see its code at http://usp.cs.utsa.edu/usp/programs/chapter11/makeargv.c) makes tokens out of the string passed as Ist argument (using delimiters passed in 2nd argument) and stores these tokens in the array pointed to by the 3rd argument.  Consider the code shown in htp://usp.cs.utsa.edu/usp/programs/chapterl1/ushl.c a) How would the shell implemented in ush1.c behave when the user gives an invalid command (i.e. a command for which no executable exists)? (5 points) b) What would happen if the user gives multiple invalid commands? (5 points) c) What happens when the user tries to quit the shell after giving multiple invalid commands. (5 points) You can assume that the makeargv0 function (see its code at http://usp.cs.utsa.edu/usp/programs/chapter11/makeargv.c) makes tokens out of the string passed as Ist argument (using delimiters passed in 2nd argument) and stores these tokens in the array pointed to by the 3rd argument

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!