An easy to use Linux Shell
-
Command Handling: Commands are basically just done by tokenizing an arg string. The built-in commands (
pwd,cd,exit) are handled in thearg_handlerfunction, while external commands are managed inexternal_cmds. -
Input/Output Redirection: Copy the read and write files into their own strings. If set then open the respective files for redirection.
-
Piping: Spilt the commands into 2 argv variables On process is forked and parent handles the other. Parent get results from child.
-
Signal Handling: Basically just created handlers that send the signals to the processes that are running and not the shell. sigchld is for preventing zombies.
-
Background: Just a flag. If set we will just not tell the shell to wait for the process to finish.
The following system calls were used:
fork(): Used for running external programs in new processes.execve(): Used to execute external programs.waitpid() & wait(): Used to wait for child processes to finish.kill(): exiting the shell, sending signals for signal handler.pipe(): piping.chdir(): Used to change the current working directory.getcwd(): Used to get the current working directory.open(): Used to open files for input/output redirection.dup2(): Used to duplicate file descriptors for redirection.
The shell was tested through various command scenarios to ensure all features were functioning as intended. The testing process included:
- Basic Command Execution: Tested built-in commands (
pwd,cd,exit) to verify their functionality. Afterwards external commands were tested (ls, cat, find, as well as my own custom programs) - Input/Output Redirection: Followed the testing with a.out reference in the assignment doc. Did output redir to create a.out and then tested input redir with cat
- Piping: Followed the find sort example in the assignment doc
- Signal Handling: Tested with wait.c which provided from lab 1
- Background Processes: Launched processes with
&to verify they could run independently without blocking the shell.