157k views
5 votes
Please write the program "mysh" in C programming language and follow the guidelines specified below. Please also include the testing code/strategies and the "test plan" describing the approach for the program along with the testing strategies. For this project, you and your partner will design and implement a simple command-line shell, similar to bash or zsh. Your program, mysh, will provide interactive and batch modes, both of which will read and interpret a sequence of commands.

This project will provide experience of
• Posix (unbuffered) stream IO
• Reading and changing the working directory
• Spawning child processes and obtaining their exit status
• Use of dup2() and pipe()
• Reading the contents of a directory
Extensions In addition to the requirements that all projects must satisfy, this assignment includes five extensions (see section 3). For full credit, your project must implement two of these extensions.
1 Overview
Your program mysh takes up to one argument. When given one argument, it will run in batch mode. When given no arguments, it will run in interactive mode.
For full credit, your program must have one input loop and command parsing algorithm that works for both modes.
Batch mode When called with an argument, mysh will open the specified file and interpret its contents as sequence of commands (see section 2). The command are given by lines of text, separated by newlines. mysh will execute each command as soon as it is complete, before proceeding to execute the next command. mysh terminates once it reaches the end of the input file or encounters the command exit.

User Nayobi
by
8.6k points

1 Answer

3 votes

Final answer:

The task is to implement a shell in C that can run in interactive or batch modes, parse inputs, create child processes, manage redirections, and use piping. Testing strategies include unit, integration, error, and performance testing, with a documented test plan.

Step-by-step explanation:

Writing a program that functions as a command-line shell in C programming language requires using system calls for process control, file operations, and inter-process communication. The project involves implementing a shell that can operate in both interactive and batch modes, processing commands from either the user input or a file. When in interactive mode, mysh will prompt the user for commands, execute them, and display the results. In batch mode, it will read commands from a specified file and execute them sequentially.

The development of mysh can be broken down into several stages:

  • Parse inputs from the command line or a file.
  • Implement the execution of commands by creating child processes using fork() and exec() family functions.
  • Handle built-in commands like changing the working directory with chdir().
  • Manage input and output redirections using dup2() and control inter-process communications with pipe().

The testing strategy for mysh involves:

  1. Unit testing individual functions for reliability.
  2. Integration testing to ensure different parts of the program work together.
  3. Testing error handling for invalid commands or arguments.
  4. Performance testing to evaluate the shell's responsiveness.

A detailed test plan should be documented which specifies the test cases, expected outcomes, and a procedure to automate the tests for consistency. Testing code can involve writing scripts to simulate user input or create batch files with a list of commands for the shell to process.

User Fysx
by
8.1k points