subject

Create a child process and execute the command entered by a user. To do this, you need to modify the main() function in shell. c so that upon returning from setup(), a child process is forked. After that, the child process executes the command specified by a user. As noted above, the setup() function loads the contents of the args array with the command specified by the user. This args array will be passed to the execvp() function, which has the following interface:
execvp(char *command, char *params[]);
where command represents the command to be performed and params stores the parameters to this command. You can find more information on execvp() by issuing the command "man execvp". Note, you should check the value of background to determine if the parent process needs to wait for the child to exit or not.
A Simple Shell
A C program that provides the basic operations of a command line shell is supplied in the file shell. c, which you can download from Canvas. This program is composed of two functions: main() and setup(). The setup() function reads in the user’s next command (which can be up to 80 characters), and then parses it into separate tokens that are used to fill the argument vector for the command to be executed. (If the command is to be run in the background, it will end with ‘&’, and setup() will update the parameter background so the main() function can act accordingly. This program is terminated when the user enters and setup() then invokes exit().
The main() function presents the prompt COMMAND-> and then invokes setup(), which waits for the user to enter a command. The contents of the command entered by the user are loaded into the args array. For example, if the user enters ls –l at the COMMAND-> prompt, args[0] will be set to the string ls and args[1] will be set to the string –l. (By "string", we mean a null-terminated, C-style string variable.)
#include #include
#define MAX_LINE 80
/** setup() reads in the next command line string stored in inputBuffer, separating it into distinct tokens using whitespace as delimiters. setup() modifies the args parameter so that it holds pointers to the null-terminated strings that are the tokens in the most recent user command line as well as a NULL pointer, indicating the end of the argument list, which comes after the string pointers that have been assigned to args. */
void setup(char inputBuffer[], char *args[],int *background) {
/** full code available in the file shell. c */ }
int main(void)
{
char inputBuffer[MAX_LINE]; /* buffer to hold the command entered */ int background; /* equals 1 if a command is followed by '&' */
char *args[MAX_LINE/+1]; /* command line arguments */
while (1){
background = 0;
printf(" COMMAND->\n"); setup(inputBuffer, args,&background); /* get next command */
/* the steps are:
(1) fork a child process using fork()
(2) the child process will invoke execvp()
(3) if background == 0, the parent will wait,
} }
otherwise returns to the setup() function. */

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 15:10
David is in week 3 of his current ashford course and has a paper due by monday night at midnight. he has finished everything but the concluding paragraph. as he boots up his computer to work on it, he sees a flash across the screen and then the screen goes black. he begins to panic as he tries desperately to turn the laptop back on. david should have saved his work on what kind of portable device?
Answers: 2
question
Computers and Technology, 23.06.2019 14:30
Select the correct answer. andy received a potentially infected email that was advertising products. andy is at risk of which type of security threat? a. spoofing b. sniffing c. spamming d. phishing e. typo-squatting
Answers: 2
question
Computers and Technology, 23.06.2019 14:30
Select the correct answer. sean is a computer programmer. he has programmed an application for toddlers that plays nursery rhymes. however, a logic error has occurred in the program. which problem is a likely consequence of the error? a. the program crashes every time the user wants to play the nursery rhymes. b. the program crosses its buffer boundaries and overwrites an adjacent program. c. the program plays a different nursery rhyme than the one the user intended to play. d. the program shows different structures in its programming language code. e. the program introduces new viruses every time the user plays a nursery rhyme.
Answers: 1
question
Computers and Technology, 23.06.2019 14:30
Select the correct answer. what does it indicate when a website displays https instead of http? a. the website is secure. b. there is no secure sockets layer. c. the secure sockets layer is hidden. d. the website is not secure.
Answers: 1
You know the right answer?
Create a child process and execute the command entered by a user. To do this, you need to modify the...
Questions
question
Social Studies, 16.03.2022 09:30
question
Mathematics, 16.03.2022 09:30