This series of Assignments are an attempt to design a custom SHELL for thw LINUX based environment. The code is written in C, and makes use of syscalls and/or manually implemented code for commands of the shell.
To see the aggregation of the project you can have a look at the Assignment3P1 folder.
Features of the shell include :
- Color based seperation of prompt-line, error-messages, directory, files and executable.
- Implementation of
pipes
andInput-Output redirection
. - Implementation of space and time efficient data-structures like
stack
andlinked-list
for commands for efficient execution. - The entire code-base is written in
C Language
with libraries used capable of running on any standardLINUX based OS
. - Implementation of
signals
and itshandling
. - A feature that shows Smile
:')
on successful execution of command and frown:'(
other-wise. - Ability to read, write and update
environment-variables
of the base OS / SHELL. - Process handling, including running a process in background, bringing it to foreground etc.
- If input file doesnot exist during redirection, the smart shell makes
stdin
as default input.
- mainP.c -> contains the main program that runs the infinite loop taking prompt (also contains code for commands like echo and pwd
- ls.c -> code for the ls command that lists out all the files of a specified directory. Implemented -a and -l flags and color coded names.
- ls.h -> header file for ls.c
- forktest.c -> contains code for running foreground and background child processes
- forktest.h -> header file for forktest.c
- cd.c -> contains code for changing directory (Not needed anymore)
- cd.h -> header file for cd.c
- hist.c -> contains code for saving/loading/displaying history.
- hist.h -> header file for hist.c logfiles/history.log contains history from previous sessions stored. (atmost 20 lines)
- pinfor.c -> contains code for displaying information of a process whose pid is given as arguments (pinfo command)
- pinfor.h -> header file for pinfor.c
- nightswatch.c -> contains code for nightswatch command
- nightswatch.h -> header file for nightswatch.c
- list.c -> implementation of linked list for history command
- list.h -> header file for list.c
- stack.c -> implementation of stack data structure for ls command
- stack.h -> header file for stack.c
- init(.sh) -> creates initial logfiles and compiles code for the first time
- compile(.sh) -> script for compiling the shell
- makefile -> to implement
make
command and create an executable namedcrash
- includefiles.h -> includes #include command required in various scripts
- constants.h -> includes constants used in code e.g. LIST_LEN is used to allocate memory to arrays, strings etc.
Go to the folder with code and compile
$ make
$ ./crash
$ ./compile.sh
$ ./crash
- The length of all commands, arrays and stacks are assumed to be 1000 in length. This is a reasonable assumption but can be increased if needed.
exit
command should be used for exit so that history can be saved.To exit type :
<username@devicename:~/path> exit
- Implementation of both
newborn
andinterrupt
in nightswatch. - To quit nightswatch we have to prompt by pressing
q
followed byreturn
. - As a feature, it seemed wise to implement that echo doesnot take
" "
into account but does take"\t"
into account (feature, not a bug). - All background processes need to be exitted and history saved, so shell will be exitted using
exit
command only. - The pinfo command is more compatible with
Linux 5.4.0.45-generic
and OSUbuntu 20.04.1 LTS (Focal Fossa)
. This is just a precautionary assumption, and is not necessarily required for the proper working of the crash shell entirely. - Maximum number of parellal instruction that can be run is 1000 but can be changed by changing value of a constant which is
LIST-LEN
. - Interrupt exits to processes is regarded failure and is greeted with a frown
To start the shell, for the first time :
$ ./init.sh
$ ./crash
For subsequent changes and compilation
$ ./compile.sh
$ ./crash.sh
VARUL SRIVASTAVA
- Roll Number : 2019111015
- E-Mail : [email protected]
- Website : Varul Srivastava | IIIT Hyderabad
- Github : https://github.com/vs666