mysh: A Basic Shell

Description

This short C program implements basic shell functionality, enabling users to run and manage programs in either "interactive" or "batch" modes. The shell will accept an arbitrary number of arguments for the specified programs. The shell also supports two commands: one to list the jobs which are currently running, and one to wait for a specified job which is currently running to finish. Accordingly, the shell allows users to specify that a job be run in the "background", in which case the user will be allowed to schedule other jobs in the meantime. Finally, users may opt to redirect output of a program via the standard redirect symbol, ">".

Implementaiton Basics

This project is written in C, and functional in both Linux and MacOS environments. When the ./mysh executable is launched within the terminal, the program provides a "shell within a shell", capable of handling up to 32 user-specified jobs simultaneously, which it does by parsing user input for up to 512 characters/line.

Design Highlights and Specifics

Process Management

This program makes use of the fork( ) and exec( ) system calls from the POSIX operating system API to launch child processes and execute binary files. It also uses the POSIX dup2( ) for redirecting standard output via file descriptors. The shell also makes use of the wait( ) and waitpid( ) calls for managing child processes, once they are created.

File I/O, String, and Basic C Functionality

This program makes extensive use of the and C libraries for the purpose of parsing user input from the shell, taking input from batch files, comparing text, writing to files, and delivering error messages. It also makes widespread use of basic C functionality such as structures, dynamically allocated memory, and pointers.

Educational Takeaways