This custom shell program, written in C, provides a basic command-line interface with several advanced features. It allows users to run standard shell commands, manage background processes, handle signal interruptions, and ensures that all commands are run as child processes of the shell.
- The shell supports all standard shell commands including piped commands, and Inupt/Output redirection.
- Commands can be executed with basic functionalities excpet, background commands and IO redirection with piping.
- Commands can be executed in the background by appending an
&at the end of the command. - Example:
$ ls -l &
- The shell supports simultaneous execution of background commands.
- By default, up to 64 commands can be run in the background at the same time.
- This limit can be adjusted via command-line argument "--max-background-processes" if needed.
- The shell acts as the parent process for all commands.
- Each command is executed as a child process, ensuring isolation and better process management.
- Example:
In this example, grep runs as a child process of the shell.
$ grep "search_term" file.txt
- Given a command with "|"(pipes) for inter process communication, the shell will split the commands, and executes each command one-by-one. The shell uses file descriptors for inter process communication.
- Each command is executed as a child process, ensuring isolation and better process management.
- Example:
In this example, the shell will return answer "8" as character counts are 8.
$ echo "Hello" | wc -c
- The shell handles iutput redirections like overwrite a file with ">" and append to a file with ">>" symbols.
- The shell also handles input redirections using "<" symbol
- Example:
- Overwrite a file with ">"
$ echo "Hello" > test.txt
- Append to a file with ">>"
$ echo "Hello" >> test.txt
- Input redirection with "<"
$ cat < test.txt
- Overwrite a file with ">"
- The shell handles the CTRL+C shortcut to kill long-running commands.
- Signal handling is implemented in C to gracefully terminate the process.
- This prevents the shell itself from being terminated and allows users to stop only the current running command.
-
Run the shell program:
$ ./shell
-
List command-line argument and get help:
$ ./shell -h/--help
-
Change default "max-background-processes" queue size:
$ ./shell --max-background-processes [INT]
-
Execute a command:
$ ls -l
-
Execute a command in the background:
$ sleep 30 & -
Terminate a long-running command with CTRL+C.
- src/shell.c: The main source file containing the shell implementation.
- src/runShellCommands.h: Header file for command execution functions.
- src/handlePipeCommands.h: Header file for handling inter process communication with pipes.
- src/handleIORedirections.h: Header file for handling IO redirections.
- src/tokenizer.h: Header file for command parsing and tokenization functions.
- To compile the shell program, you can use the Makefile available in the "src" folder as follows:
- Compile the program
$ make
- Clean compiled files
$ make clean
- Compile the program