This repository contains the implementation of a basic shell in C, created as part of a lab exercise to deepen understanding of process management in Linux.
- Execute Basic Linux Commands: The shell accepts user input, forks a child process, executes the command using the
execsystem call, and reaps the child using thewaitsystem call. - Prompt: The shell uses
$as the command prompt and continues to run until terminated by Ctrl+C. - Error Handling: Handles errors gracefully, including empty commands and invalid input. Does not crash and displays an appropriate error message.
- Change Directory (
cd): Supportscdto change the current working directory.
- Background Processes: Supports background execution of processes using the
&operator. Background processes do not block the shell from accepting new commands. - Child Reaping: Reaps background processes periodically when receiving new input.
exitCommand: Allows the shell to exit gracefully by terminating all background processes and cleaning up resources.
- Signal Handling: The shell catches the Ctrl+C signal (SIGINT) and ensures that only the foreground process is terminated. The shell itself continues running.
- Serial Execution: Commands separated by
&&are executed sequentially. - Parallel Execution: Commands separated by
&&&are executed in parallel.
- Linux Environment: The shell is developed and tested in a Linux environment.
- GCC Compiler: Ensure that GCC is installed to compile the shell.
To compile the shell, run:
gcc myshell.c -o myshellTo run the shell, use:
./myshellOnce running, the shell will display the $ prompt, where you can enter commands.
- Basic Linux commands like
ls,cat,echo, andsleep. - cd command to change directories.
- Background execution using
&. - Serial execution using
&&. - Parallel execution using
&&&. - exit command to terminate the shell.
$ ls
file1.txt file2.txt
$ sleep 10 &
$ cd ..
$ exit