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
PLz answer I really need the answer
zlopas [31]

Answer:

a

Explanation:

job leads

4 0
3 years ago
Read 2 more answers
Java programming
Marat540 [252]

Answer:

The program in Java is as follows:

import java.util.*;

public class Main {

public static void removeDuplicate(ArrayList<Integer> list){

 ArrayList<Integer> newList = new ArrayList<Integer>();

 for (int num : list) {

  if (!newList.contains(num)) {

   newList.add(num);  }  }

 for (int num : newList) {

     System.out.print(num+" ");  } }

public static void main(String args[]){

 Scanner input = new Scanner(System.in);

 ArrayList<Integer> list = new ArrayList<Integer>();

 System.out.print("Enter ten integers: ");

 for(int i = 0; i<10;i++){

     list.add(input.nextInt());  }

 System.out.print("The distinct integers are: ");

 removeDuplicate(list);

}}

Explanation:

This defines the removeDuplicate function

public static void removeDuplicate(ArrayList<Integer> list){

This creates a new array list

 ArrayList<Integer> newList = new ArrayList<Integer>();

This iterates through the original list

 for (int num : list) {

This checks if the new list contains an item of the original list

  if (!newList.contains(num)) {

If no, the item is added to the new list

   newList.add(num);  }  }

This iterates through the new list

 for (int num : newList) {

This prints every element of the new list (At this point, the duplicates have been removed)

     System.out.print(num+" ");  } }

The main (i.e. test case begins here)

public static void main(String args[]){

 Scanner input = new Scanner(System.in);

This declares the array list

 ArrayList<Integer> list = new ArrayList<Integer>();

This prompts the user for ten integers

 System.out.print("Enter ten integers: ");

The following loop gets input for the array list

<em>  for(int i = 0; i<10;i++){ </em>

<em>      list.add(input.nextInt());  } </em>

This prints the output header

 System.out.print("The distinct integers are: ");

This calls the function to remove the duplicates

 removeDuplicate(list);

}}

5 0
3 years ago
How does predation differ from parasitism?How does predation differ from parasitism?Parasites rarely kill their host while preda
enyata [817]

Answer:

The right answer is: Parasites rarely kill their host while predators kill their prey.

Explanation:

parasites are organisms that feed on substances obtained from other living beings that they use as hosts, therefore, they do not need to kill them, on the contrary, they need them to be alive to be able to feed. some parasites live inside and others outside the host, the latter usually do not harm it, but many of those who live inside generate damage, being able even to kill them.

The predators, by the other hand, seek their prey, trap it, and eat it. predators can be hunters of diferents species

5 0
3 years ago
Write a program that reads a list of integers, and outputs whether the list contains all even numbers, odd numbers, or neither.
Ivahew [28]

Answer:

def is_list_even(list):  

 return all((x % 2) == 0 for x in list)  

def is_list_odd(list):

 return all((x % 2) == 1 for x in list)  

numberList = []  

n = int(input("Enter number of elements : "))  

for i in range(0, n):  

 numberList.append(int(input()))

if is_list_even(numberList):

 print("all even")

elif is_list_odd(numberList):

 print("all odd")

else:

 print("not even or odd")

7 0
3 years ago
Consider the following page reference string:
denpristay [2]

Answer:

a) 18

b) 17

c) 13

7 0
3 years ago
Other questions:
  • What is requirement analysis
    8·1 answer
  • What is the difference between "call by value" and "call by reference"? Explain with example in c language.
    7·1 answer
  • What is DAP? How LDAP is different from DAP?
    10·1 answer
  • How can a user preview the playback of an audio clip in PowerPoint? Use the drop-down menus to complete the statements.
    14·1 answer
  • Why 3 phase motors so effective?
    5·1 answer
  • I AM GIVING BRAINLEST!!!!!!!!
    14·2 answers
  • What is the main fuction of command interpreter​
    11·1 answer
  • Which of the following is NOT AN EXAMPLE of personal identifying
    9·2 answers
  • assume there are K sorted lists, each of n/k elements. We want to merge them into a single sorted list of n elements. Give an op
    7·1 answer
  • 2. When you establish a connection to a remote host using Remote Desktop Connection, what appears at the top of the screen that
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!