1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Vikki [24]
2 years ago
7

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.
Computers and Technology
1 answer:
asambeis [7]2 years ago
6 0
Where is the question
You might be interested in
25 POINTS + BRAINLIEST PLS HELPWhere should you put the argument for a command?
Maslowich

d. on. the. line. just. after the. command

8 0
3 years ago
A look to different section of the same page is known as_____.
11Alexandr11 [23.1K]

Answer:

hatdoggggggggg

Explanation:

sunoggggggg

6 0
2 years ago
Short note about micro miniaturzation​
Ghella [55]

Answer:

the manufacture of extremely small versions of electronic devices.

3 0
2 years ago
Read 2 more answers
Friday Night Funkin Fans, does this count as a leak if I share it?
Aliun [14]
Hmm no I don’t think so
7 0
2 years ago
Read 2 more answers
Select the best answer for the question. 2. What is the simplest way to permanently get rid of an unwanted file?
Kobotan [32]
To permanetly get rid of an unwanted file, you delete it
3 0
2 years ago
Other questions:
  • What does utp stand for?
    11·2 answers
  • Application partitioning gives developers the opportunity to write application code that can later be placed on either a client
    7·1 answer
  • Write a program Gas.java that computes and displays the price a person will pay for gas at the gas station. The program takes th
    12·1 answer
  • A TCP ________ segment is a request to the other transport process to close a connection. ACK FIN SYN CLS
    15·1 answer
  • Difrent between computer and computer system​
    9·1 answer
  • Explain the main components of a computer system​
    12·1 answer
  • I love my baby boy and can someone help me with this
    6·1 answer
  • Tại sao xe chỉ sản xuất ra 1996cc mà không phải là 2000cc?
    6·2 answers
  • Need Help Please
    7·1 answer
  • The math function ceil(x) returns the smallest integer that is greater than or equal to x. True False
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!