Question: Please help me with this C function. We are modifiying the existing C code called msh.c given below but leave the existing functions there. We
Please help me with this C function. We are modifiying the existing C code called msh.c given below but leave the existing functions there. We are required to use fork and exec to run Linux commands while running that function. The example on how to use fork and exec is also given. We are compiling it using gcc. The code for msh.c is given below after the instructions. Please post screenshots of your code and output since it is easier to see the format that way. Thank You!
Instructions/Requirements:


//msh.c
#include #include #include #include #include /* * A very simple shell */ #define MAX_BUF 160 #define MAX_TOKS 100 int main() { char *pos; char *tok; char s[MAX_BUF]; char *toks[MAX_TOKS]; time_t rawtime; struct tm *timeinfo; static const char prompt[] = "msh> "; while (1) { // prompt for input printf(prompt); // read input char *status = fgets(s, MAX_BUF-1, stdin); /* exit if ^d or "exit" entered */ if (status == NULL || strcmp(s, "exit ") == 0) { if (status == NULL) { printf(" "); } exit(EXIT_SUCCESS); } // otherwise echo user input printf(s); } } . as before, exit msh when 'exit or ctri-d is entered, and always echo the user input . run Linux commands that are entered by the user. You must do this by using fork and exec as shown in OSTEP Figure 5.3 After a command is executed, the prompt should be displayed as usual I recommend that you implement this feature by first breaking the user input into "tokens". The tokens are the strings in the input line separated by whitespace (spaces or tabs). The tokens should not include any whitespace. For example, on input msh> wc -l there are two tokens: "wc" and "-I". Hint: use C librarv function 'strtok' to break the user input into tokens include #include #include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
