subject

The program allows the user to type in any linux command and then executes that command, such as "pwd" or "echo". The problem is that it should allow multiple commands to be typed in and executed at the same time, but it only allows one at a time currently. Please help fix it so it allows multiple commands to be typed and executed. Code:
#include
#include
#include
#include
#include
#include
void parse(char *line, char **argv)
{
while (*line != '\0') { /* if not the end of line */
while (*line == ' ' || *line == '\t' || *line == '\n')
*line++ = '\0'; /* replace white spaces with 0 */
*argv++ = line; /* save the argument position */
while (*line != '\0' && *line != ' ' &&
*line != '\t' && *line != '\n')
line++; /* skip the argument until ... */
}
*argv = '\0'; /* mark the end of argument list */
}
void execute(char **argv)
{
pid_t pid;
int status;
if ((pid = fork()) < 0) { /* fork a child process */
printf("*** ERROR: forking child process failed\n");
exit(1);
}
else if (pid == 0) { /* for the child process: */
if (execvp(*argv, argv) < 0) { /* execute the command */
printf("*** ERROR: exec failed\n");
exit(1);
}
}
else { /* for the parent: */
while (wait(&status) != pid) /* wait for completion */
;
}
}
void main(void)
{
char line[1024]; /* the input line */
char *argv[64]; /* the command line argument */
while (1) { /* repeat until done */
printf("Enter Shell Command -> "); /* display a prompt */
fgets(line, 1024, stdin); /* read in the command line */
printf("\n");
parse(line, argv); /* parse the line */
if (strcmp(argv[0], "exit") == 0) /* is it an "exit"? */
exit(0); /* exit if it is */
execute(argv); /* otherwise, execute the command */
}
}
This function receives a commend line argument list with the */ /* the first argument being cd and the next argument being the */ /* directory to change.

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 06:30
What result from the passage of this amendment
Answers: 1
question
Computers and Technology, 22.06.2019 08:00
What is the first step in creating a maintenance ?
Answers: 2
question
Computers and Technology, 22.06.2019 19:20
Consider the following code snippet: #ifndef cashregister_h#define cashregister_hconst double max_balance = 6000000.0; class cashregister{public: cashregister(); cashregister(double new_balance); void set_balance(double new_balance); double get_balance() const; private: double balance[12]; }; double get_monthly_balance(cashregister bk, int month); #endifwhich of the following is correct? a)the header file is correct as given.b)the definition of max_balance should be removed since header files should not contain constants.c)the definition of cashregister should be removed since header files should not contain class definitions.d)the body of the get_monthly_balance function should be added to the header file.
Answers: 1
question
Computers and Technology, 22.06.2019 22:40
Write a program that defines symbolic names for several string literals (chars between quotes). * use each symbolic name in a variable definition. * use of symbolic to compose the assembly code instruction set can perform vara = (vara - varb) + (varc - vard); ensure that variable is in unsigned integer data type. * you should also further enhance your symbolic logic block to to perform expression by introducing addition substitution rule. vara = (vara+varb) - (varc+vard). required: debug the disassembly code and note down the address and memory information.
Answers: 3
You know the right answer?
The program allows the user to type in any linux command and then executes that command, such as "pw...
Questions
question
Mathematics, 20.09.2020 01:01
question
Mathematics, 20.09.2020 01:01
question
Geography, 20.09.2020 01:01
question
Mathematics, 20.09.2020 01:01
Questions on the website: 13722367