Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribed

image text in transcribed

//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 4 #include #include 7int 8 main (int argc, char argv (pid:%d) ", (int) getpid()); printf ( "hello world int rc = fork(); if (rc

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

Database Design Application Development And Administration

Authors: Michael V. Mannino

3rd Edition

0071107010, 978-0071107013

More Books

Students also viewed these Databases questions