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]
3 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]3 years ago
6 0
Where is the question
You might be interested in
HURRY MY COMPUTER IS ABOUT TO DIE ILL GIVE BRAINLYESTn
loris [4]

Answer: D, C, E, are the answers! good luck.

Explanation:

5 0
3 years ago
This is computer and programming
miv72 [106K]

Answer:yes

Explanation:because

3 0
3 years ago
Read 2 more answers
Implement a simplified version of a crypto broker platform. Initially, there is an array of users, with each user depositing onl
Salsk061 [2.6K]
Jriririiekeekekkksks
3 0
3 years ago
Holly created a professional development plan to explore how she could advance from her entry-level position to the next step in
Sunny_sXe [5.5K]
A.) Ask a colleague for advice work life balance
3 0
3 years ago
Read 2 more answers
‘The increased availability of mobile digital devices has had a positive impact on how young people use their free time’. Make a
Law Incorporation [45]
"The increased availability of mobile digital devices has had a positive impact on how young people use their free time."

There are many different views that you could take upon this subject.  

1) You could say that the increased availability of mobile digital devices has allowed children to increase their academic success, by being able to search for and complete assignments using these devices.

2) You could say that the increased availability of mobile digital devices allows for children to occupy themselves by providing games, videos, books, and other things to provide them with entertainment, a learning experience, and more.

Hope this helps!
4 0
3 years ago
Other questions:
  • What does this mean?
    7·2 answers
  • At what point in a vulnerability assessment would an attack tree be utilized?
    9·1 answer
  • Know when the double, int, String, and char data types are best used. Example: I would store a social security number in a strin
    7·1 answer
  • مسألة لبرنامج الماتلاب لمصفوفة وعمود
    10·1 answer
  • Which of the following statements comparing debit cards to credit cards is TRUE?
    13·2 answers
  • What do u mean by software​
    7·1 answer
  • Which of the following involves unethical use of another’s intellectual property?
    13·1 answer
  • Points! taga pilipinas ba kayo?​
    10·1 answer
  • What does it mean to influence the government? Use influence in a sentence.
    8·2 answers
  • On what type of network can you rent things such as cars, tools, and rooms?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!