Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This code keeps giving me a sergetation fault #include #include #define MAX_LINE 80 /* The maximum length command */ int main (void) { char *args[MAX_LINE/2

This code keeps giving me a sergetation fault

#include

#include

#define MAX_LINE 80 /* The maximum length command */

int main (void)

{

char *args[MAX_LINE/2 +1]; /* command line arguments */

int should_run = 1; /* flag to determine when to exit program */

while (should_run) {

printf("CSCI3120>");

fflush(stdout);

char *temp;

char *token;

int i = 0;

scanf("%s", &temp);

token = strtok(temp, " ");

while( token != NULL ){

args[i] = token;

printf(" %s ", token);

token = strtok(NULL, " ");

i = i + 1;

}

int j = 0;

while (i > j){

printf(args[j]);

j = j + 1;

}

/**

*After reading user input, the steps are:

*(1) fork a child process using fork()

*(2) the child process will invoke execvp()

*(3) if command included &, parent will invoke wait()

*/

}

return 0;

}

image text in transcribed

This args array will be passed to the execvp) function, which has the following prototype: execvp (char *command, char *params []) Here, command represents the command to be performed and params stores the to this command. For this project, the execvp( function should be invoked as parameters execvp (args[0], args) Be sure to check whether the user included an & to determine whether or not the parent process is to wait for the child to exit

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 Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

3. How would you address the problems that make up the situation?

Answered: 1 week ago

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago