This is the implementation of a Linux shell written in C language.
- Run the command
make
on your terminal. - Run
./angel
to get a prompt of the form<username@system_name:path>
. - Run any command in the shell. It can entail as many number of tabs and spaces, the shell accounts for those.
- In order to exit, run
exit
.
These commands have been defined by me and are contained within the shell itself.
-
pwd
-
ls [-l -a] [directory]
- Lists all the files and directories in the specified directory in alphabetical order.
- Variations such as
ls, ls . , ls .., ls ~, ls -la / ls -al, ls -a -l
also work. - Also handles multiple directories as arguments. eg.
ls [-l -a] dir1 dir2 dir3
. - Throws error if you try to
ls
on anything except a directory or a file. - Implemented in ls.c.
- Function Declarations are in ls.h.
-
cd [file]
-
echo [arguments]
-
exit
- Exits the shell.
-
promtpinting
-
repeat
-
Command Handler
-
headers.c
- Contains some common headers and libraries.
- Implemented in headers.h
-
signalHandlers.c
- Contains signal checker for any suspeneded or exited background process.
- Also contains the signal controllers for Ctrl+C & Ctrl+Z.
- Implemented in signalHandlers.h.
-
bg [JobIndex]
-
fg [JobIndex]
-
sig [JobIndex] [SIGNAL]
-
jobs [-r -s]
- Prints a list of all currently running background processes in alphabetical increasing order as Running or Stopped.
- If the flag specified is -r, then only the running processes are displayed
- If the flag is -s then the stopped processes are printed.
-
pipe.c
- This file is used to implement the pipe and I/O Redirection within Command Pipelines functionality in the commands.
- I basically parse the pipes by the
|
symbol and then execute each subsequent command. - For example in
c1 | c2 | c3
, initially, I tokenize the commands by|
symbol. Then each of the commands is run sequentially such that the output of one command becomes the input of the following command usingdup(), dup2() & fork()
.
-
redirection.c
- This file contains code for the Input/Output redirecting functionality i.e,
<, >, >>
. - Both input and output redirection can be used simultaneously.
- The created output file has permissions 0644 if it does not already exist.
- In case the output file already exists, then it overwrites in case of
>
and appends to in case of>>
.
- This file contains code for the Input/Output redirecting functionality i.e,
-
CTRL-Z, CTRL-C, CTRL-D
CTRL-Z
- Pushes any currently running foreground job into the background, and change its state from running to stopped. This has no effect on the shell if there is no foreground process running.CTRL-C
- Interrupts any currently running foreground job, by sending it the SIGINT signal. This has no effect on the shell if there is no foreground process running.CTRL-D
- Logs the user out of the pseudo shell, without having any effect on the actual terminal.- Implemented in sig.h, sig.c & main.c.
-
replay -command <command> -interval <timeInterval> -period <timePeriod>
-
baywatch [-n] dirty
-
makefile
- This file contains the code to run the shell. To compile the shell, run:
make
- After compilation, to start the shell run:
./angel
- This file contains the code to run the shell. To compile the shell, run:
- Upon termination of a background process, the shell prints its PID and exit status.
- Handles foreground processes
&
when it is in the end and prints the[PID]
of the process. - Implemented in foregroundProcess.c and backgroundProcess.c.
- Function Declarations are in foregroundProcess.h and backgroundProcess.h.
-
pinfo [PID]
-
history [num] or history
- Lists the last [num] commands. If no arguments are specified, it displays the last k commands where k <= 10.
[num]
should be less than 20.- Retains the
history
even upon Shell exit - uses angelHistory.txt. - Implemented in history.c
- Function Declarations are in history.h.
The code is completely modular with different .c
files for each command, and a main.c
binding them all together. The files ending with .h
entails all the necessary header files, and global variables.