This is my implementation of a shell. Initially created to develop a deeper understanding of the Linux OS. However, I intend to make this as good as, if not better than Bash. This shell was written entirely in C. Some functions were implemented from scratch, while the rest made use of the exec() family of functions. The commands in this shell are semicolon separated. It also supports redirection and piping, and supports the Ctrl + Z
, Ctrl + C
and Ctrl + D
signals.
The shell has a cyan
and yellow
theme for prompt and a red
and magenta
theme for error messages.
cd
pwd
echo
ls
pinfo
repeat
jobs
sig
fg
bg
replay
- Download all the files and put them in a certain directory
- Navigate to that directory from the terminal
- Now just run
make
. This will create an executableash
file - Now run
./ash
to execute this file ash
may not have execute permissions, in which case runchmod +x ash
, and then run./ash
again- That is all :)
- Includes all the necessary header files.
- Defines some global variables
- Includes a structure to handle background processes.
- Defines the functions used across the shell.
- Contains all the global variables used in the shell.
- Gets the SIGCHLD signal ready
- Initializes the process structure
- Loop to run the shell
- Kills zombie children
- Calls ash_main.c
- Displays the banner ie < uname @ hostname : cwd >
- Accepts user input
- Parsed the input to individual commands and executes each command one by one
- Calls ash_execute.c
- Gets the command word from the parsed input ie cd ---> cd
- Calls the respective function using the command word
- Implements the bash cd command
- Implements the bash pwd command
- Implements the bash echo command
- Extracts the
path
from the input - Calls ash_ls.c with
path
as input
- Implements the bash ls command
- This one was tough :(
- Displays Process ID
- Process Status
- Process Memory
- Process Path
- Repeats a command n times
- Supports piping
- Supports redirection
- Syntax : jobs -
- Lists the processes spawned by this shell
- -r flag lists only the running processes
- -s flag lists only the stopped processes
- -rs lists both running and stopped process, is equivalent to no flags
- Syntax : sig <process_position> <signal_number>
- Sends the specified signal to the process with the given position
- Syntax : bg <process_position>
- Changes the status of a process from stopped to running
- Syntax : fg <process_position>
- Brings a process to the foreground
- Executes a command after a certain interval for a certain period of time
- Executes other commands using the exec family of functions
- Handles forking
- Initializes the process structure
- Pushes a child to the process structure
- Kills zombies ie Closes running processes after ash is closed
- Handles SIGCHLD, SIGTSTP, SIGINT signals
- Ctrl C terminates a foreground process
- Ctrl Z pulls a foreground process to the background
- Contains utility type functions
wprint()
is basicallywrite()
, made for conveniencecprint
is a specializedprintf
to display error messages in color- The rest have self-explanatory names
- Used for compilation
- Run this using
make
command
ash
can run 1024 background processes. This can be changed in theshell.h
file. There are certain size limitations on the length of input strings, but it is more than enough for reasonably sized commands. Any errors will soon be fixed.
- Readability was a priority while writing this code.
- Functions are named with the snake case convention ie function_name.
- The code is highly modularized. Many functions were used.