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
avanturin [10]
3 years ago
12

In this assignment, you will write a complete C program that will act as a simplecommand-line interpreter (i.e., a shell) for th

e Linux kernel. In writing your shell, you areexpected to use the fork-exec-wait model discussed in class. In particular, you are toimplement the following:• Loop continuously until the user enters quit, which exits your shell.• Inside the loop, you will print your "minor5" prompt and read in the user’scommand, which may consist of a Linux command with 0 or more options andarguments supported by the command. You are expected to read in and processonly 1 command at a time with no pipelining or redirection.• In a child process, you are to execute the command as given, including alloptions and arguments given. If the command is not valid, rather than display an"exec failed" message as shown in class examples, you will simply print outthe command itself with "command not found" as shown in the SAMPLEOUTPUT and then exit the child process. The parent process should wait for thechild process to finish.If you have any questions about this, please contact your instructor, TAs, or IAsassigned to this course to ensure you understand these directions.SAMPLE OUTPUT (user input shown in bold):$ ./a.outminor5> lsa.out grades.txt rec01.txt testdir phone.txt route.txt who.txtdu.txt rec01.c file1 rec01sol.c minor5.cminor5> ls -a -l -ttotal 144-rwx------ 1 cat0299 cat0299 7835 Oct 14 17:39 a.outdrwx------ 4 cat0299 cat0299 4096 Oct 14 17:39 .-rw------- 1 cat0299 cat0299 2665 Oct 14 17:39 minor5.c-rw------- 1 cat0299 cat0299 33 Oct 5 03:30 du.txt-rw------- 1 cat0299 cat0299 33 Oct 5 01:28 file1-rw------- 1 cat0299 cat0299 333 Oct 5 01:02 route.txt

Computers and Technology
1 answer:
jolli1 [7]3 years ago
7 0

Answer:

/ to access the input scanf()

// and output printf()

#include <stdio.h>  

// to access the functions like

// pipe(), fork(), execvp(), dup2()

#include <unistd.h>  

// to access the string functions like

// strtok()

#include <string.h>

// to access function wait()

#include <sys/wait.h>

#include <stdlib.h>

int main()

{

  // declare a variable to hold the process id

  pid_t p_id;

  // declare a variable to hold the index value

  int array_index;

  // declare the string to hold the user input

  // as command

  char userIn_Command[128];

  // use a continuous loop

  while (1)

  {

      // display the prompt for the user

      printf("minor5> ");

      // read the input from the user

      scanf("%[^\n]", userIn_Command);

      // check the condition that whether the user

      // inputs a command called "quit"

      // If the user inputs quit command then exit from

      // the script

      if (strcmp(userIn_Command, "quit") == 0)

      {

          printf("\n");

          break;

      }

      // if there are any usage of pipelining or redirection

      // display the error message and exit from the script

      if (strchr(userIn_Command, '|') != NULL || strchr(userIn_Command, '>') != NULL ||

          strchr(userIn_Command, '<') != NULL)

      {

          printf("Error: Cannot perform the multiple command operations or directions\n");

          break;

      }

      // declare the variables to hold the process

      int p_pids[2];

      // create the system call to pipe() from kernal

      // and display the error message

      if (pipe(p_pids) < 0)

      {

          printf("Error: Pipe creation failed!\n");

      }

      // create the child process

      p_id = fork();

      // condition to check whether the fork() is

      // created. If so, display an error message

      if (p_pids < 0)

      {

          printf("Error: fork() failed!\n");

          break;

      }

      // if the child process is created

      if (p_id == 0)

      {

          // close pipe in child process

          close(p_pids[0]);

          // create duplicate of the standard output

          dup2(p_pids[1], STDOUT_FILENO);

          // close the pipe in child process

          close(p_pids[1]);

          // declare a variable to store path

          // to execute the command

          char *command_path;

          // declare an array of string to hold the options

          char * args[32];

          // tokenize the command by using the delimiter at " "(single space)

          char *cmd_token = strtok(userIn_Command, " ");

          // store the token value

          command_path = cmd_token;

          args[0] = cmd_token;

          array_index = 1;

          // loop until all the options in the command are

          // tokenized

          while (1)

          {

              // get the next token

              cmd_token = strtok(NULL, " ");

              // condition to check whether the token is null

              // or not

              if (cmd_token == NULL)

              {

                  break;

              }

              // store the token if it is not null

              args[array_index] = cmd_token;

              // increment the index

              array_index++;

          }

          // last parameter to the command should be NULL */

          args[array_index] = NULL;

                     

          /* calling exec function with command path and parameters */

          if (strcmp(args[0], "cd") == 0 || strcmp(args[0], "history") == 0 ||

              strcmp(args[0], "exit") == 0)

          {

              printf("%s: Command not found\n", args[0]);

              break;

          }

          if (execvp(command_path, args) < 0 )

          {

              printf("%s: Command not found\n", args[0]);

              break;

          }

      }

      else

      {          

          /* closing writing end of pipe in parent process */

          close(p_pids[1]);

          /* reading ouput written to pipe in child process and

          * writing to console */

          while (1)

          {

              char output[1024];

              int n = read(p_pids[0], output, 1024);

              if (n <= 0)

              {

                  break;

              }

              output[n] = '\0';

              printf("%s", output);

          }

          /* closing read end of pipe1 */

          close(p_pids[0]);

          /* waiting until child process complete its execution */

          wait(NULL);

      }

      /* skipping newline character read while scanf() */

      getchar();

  }

  exit(0);

}

Explanation:

You might be interested in
The amount of ram that is actually on the memory modules in your computer is the ________ memory.
viva [34]
I think its physical memory but I am defiantly not confident about 90%
6 0
3 years ago
Under which menu option of a word processing program does a star appear
alexandr1967 [171]

Answer:

Under the menu option Insert.

Explanation:

Microsoft word allows you to insert different shapes in the document. To find these shapes, you have to open the menu option Insert. Then, you will have to go to Shapes. After that, you have to click there and a box will appear where you will have different shapes that you can use. There you will find the shape of a star that you can include in the document and adjust different features like size and color.

5 0
3 years ago
Read 2 more answers
Fill up the blank:- The picture that graphically represents the items you use in Windows is called a/an .......
vagabundo [1.1K]
The picture that graphically represents the items you use in Windows or any other OS is called an Icon. An icon is a picture that represents the program that is being used. An icon is useful for the user's to directly know what type of program they need to use or such.
8 0
3 years ago
As John develops the agenda, he wants to put the name of the appropriate person next to the agenda item. Whose name would he put
tresset_1 [31]

Answer:

d. His own

Explanation:

John is the JAD project leader

Joint Application Development (JAD) is a process that accelerates the design of information technology solutions. JAD uses customer involvement and group dynamics to accurately depict the user's view of the business need and to jointly develop a solution.

The executive sponsor is the person from the customer's organization who has the ultimate authority to make decisions about the project. The sponsor may be the customer's project leader, the CIO, or, in some cases, the CEO. The facilitator works with the sponsor to get the project started; it is essential, however, that the sponsor make key decisions, not the facilitator.

The executive sponsor has the following responsibilities:

. Accept ultimate authority and responsibility for the functional area to be addressed by the system.

· Resolve business policy conflicts by being the ultimate decision? maker.

· Honor the results of the JAD process.

· Set the vision for the project.

· Ensure the project team has access to and commitment from the right business user experts.

· Communicate customer support and cooperation.

6 0
3 years ago
This is the question
nikdorinn [45]

Answer:

I dont know it sorry

Explanation:

i would help u

4 0
3 years ago
Other questions:
  • Most modern TCP implementations use pseudo-random number generators (PRNG) to determine starting sequence numbers for TCP sessio
    13·1 answer
  • What is a different paragph formatting tools
    6·1 answer
  • On dynamic disks, the term partition is not used to define the space where a file system is installed. what term is used?
    6·1 answer
  • Explain the term DNS(Domain Name System) and why it is used.
    9·1 answer
  • Java Question-5 Declare and initialize two variables called first and second. Write a single statement that will print the messa
    15·1 answer
  • Prompt the user for a character and the height of a right triangle. Then, print a triangle of that height using the character en
    11·1 answer
  • Websites whose URL’s contain tildes (~) are usually published by the government. True or false?
    8·2 answers
  • What is the function of the &lt; !Doctype &gt; tag?
    12·2 answers
  • Which of the following statements is true? The Wireshark protocol analyzer has limited capabilities and is not considered multi-
    15·1 answer
  • Write a qbasic program to display integer numbers 1 to 100 using the for next loop<br>​
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!