Skip to content
Garrett-HPublic

About

Memory Efficient SHell

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Memory Efficient Shell (MESH)

A basic command line Unix shell written as an attempt to maximize memory efficiency.

Design Overview

Structure

  1. MESH takes an input line (interactive = "stdin", batch = "File* Stream) dynamically increasing the buffer size until the end of the line.
  2. MESH then parses the input line into separate c strings for each command.
  3. MESH next parses the commands into an array of c strings that are separated by each argument.
  4. MESH finally uses a custom forker to fork and simultaneously execute each command on the original line
    1. The forker also checks for the exit/quit command and sends a signal back to main program to exit once all commands are executed.
  5. MESH then loops until "exit","quit", or EOF are called.
    1. "CTRL+D" is counted by the system as an manual EOF so the program also exits then as well.
  6. Frees any remaining dynamic pointers and returns "0".

Specifications

  • The dynamic buffers are reallocated once all changes are completed for them, so as to not take any extra space.
  • The dynamic buffers act as vectors when resizing themselves, starting at chunks of 8 of specific types.
  • "execvp" was used as the executor as to auto include "$PATH" elements.
  • incorrect number of arguments for the program indicates, "Too many arguments" and Exits the program.
  • empty inputs and extra whitespace are removed at parsing and are not forked or executed.
  • As "strtok()" function used in parsing does not declare new dynamic memory they are freed along with original input buffer at exiting program.

Compilation

Requires preferably POSIX compliant system and gcc
Use the Makefile provided to compile the code to an executable.

make

Usage

To enter 'interactive mode' directly call the executable

./mesh

To use 'batch mode' call the executable with a singular file as a argument

./mesh foobar

To exit the program enter into the shell 'exit' or 'quit' as a command

READY > exit

Objectives

  • Interactive & Batch Modes
  • Multiple Commands via seperators ";","|", and "&"
  • Simultaneous execution of multi-commands
  • Defensive Programming with multiple error checks
  • Unrestricted limit of characters via dynamic memory allocation
  • Messages to "stderr" for multiple arguments in execution
  • Makefile made.
  • Readme created via Github Markdown.
  • Runs normally on cs2 server.

Bugs

When echoing the command line from batch files the last line will print after the commands are executed.

Contributors

Garrett Hay

License

MIT

About

Memory Efficient SHell

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages