In the directory containing the source code, execute:
$ make
$ ./a.out
- Prompt is displayed in the same format as in BASH with username, system name and current working directory. Home directory ("~") is considered as the directory from which the shell a.out was executed.
- Errors while getting the current working directory (home directory), username or system name leads to termination of the shell.
Input : multiple commands can be given separated by ;
.
Extra whitespaces given in commands or arguments is ignored.
Error checking : If any command fails to execute due to mulitple reasons, the relevant error message will be printed to the terminal by use of perror
and in some cases without perror
. That command will be skipped and shell will continue to run.
pwd
- prints the absolute path of the current working directory.echo
- prints whatever is given as argument as it iscd
- changes the cwd to the mentioned directory, if no argument, changes to the home (~) directory.- arguments:
.
,..
,-
,~
, any relative/absolute path to a directory
- arguments:
ls
- lists all the files/directories of the place passed as arguments, or if none pased the cwd.- flags:
-a
,-l
,-a -l
,-l -a
,-al
,-la
. where a is for all, and l is for long. - Supports mulitple directories as arguments. If mulitple directories are given along with flags, the flags apply to all directories.
- flags:
repeat
- takes an argument num command, and executes the mentioned command num times.history
- by default prints the last 10 typed commands of shell, or if lesser than 10 available, then print them.
- with flag num. Prints last num commands from history. 1 < num < 21.
- Maximum of 20 commands are stored in the history.
- On closing the shell by using
CTRL+D
orexit
orquit
, the history is saved to a file.shell_history
in the home directory. History is loaded from the same file for other shell sessions. - If the file
.shell_history
is not formed yet, or is unreadable, it is ignored. Errors are generated if writing to this file is problematic. Up Arrow
- on pressing the up arrow, recent commands can be seen in the order newer to older.Down Arrow
- on pressing the down arrow, recent commands can be seen in the order older to newer.
pinfo
- displays the details of a process with pid passed as argument.- If no argument passed, the pid of the running shell is considered.
- Other commands from Bash - executed with the help of
execvp
command. jobs
- List all the background processes of the shell, with Job_Num, status (either Running or Stopped), Name, PID.- The result is sorted albhabetically by the Name of the command, and then by the Job Num.
- The
Job Num
is alloted by the shell and changed dynamically as the processes are killed/terminated from the background. - The
Job Num
is given sequentially, a process starting earlier will have lower Job Num.
sig
- Takes the argument job_num which is made by the shell and signal which is sent to the process corresponding to that job num. Errors are printed if its not successful in sending the signal.fg
- Takes the argument job_num which is made by the shell. It brings any background process of the shell to foreground. It also changes the state of the process to running.bg
- Takes the argument job_num which is made by the shell. It continues any stopped process which is in the background, if its already running, it will be ignored.replay
- Syntax:replay -command <command> -interval <i> -period <p>
- It repeats the given command
<command>
in intervals of<i>
and upto total time period of<p>
. - It is started as a foreground process, so the shell is blocked and cannot be used for other commands before completion of
replay
. - The whole time taken by
replay
is equal to<p>
irrespective the value of<i>
.
- It repeats the given command
baywatch
- Syntax:baywatch -n <seconds> command
.- It repeats the command in intervals of
-n
untillq
is pressed. wherecommand
can be:interrupt
- print the number of times the CPU(s) have been interrupted by the keyboardcontroller (i8042).
Used the file/proc/interrupts
to find this information.newborn
- print the PID of the process that was most recently created on the system.
Used the file/proc/loadavg
to find this information.dirty
- print the size of the part of the memory which is dirty.
Used the file/proc/meminfo
to find this information.
- It repeats the command in intervals of
- Foreground process - execution of process that happen in the foreground. These take away control from shell and must be finished/terminated to regain control of the shell.
- Background process - any command passed with
&
flag is treated as background process. The user can use the shell normally without waiting for completion of command. The pid of child process is printed to terminal when command is executed. - Finishing of Background process - a message is printed whenever a background process is completed/terminated, expressing whether is was normal or abnormal termination.
- Piping - The shell supports
|
piping, which transfers the input and output from one command to another instead of the terminal and thus allows interprocess communication. Implemented usingdup
anddup2
. It can also be used in combination with Redirection. - Redirection - The shell supports
<
,>
,>>
redirections. Through this the commands can give output and take input from files present in the computer. Implemented usingdup
anddup2
. It can also be used in combination with Piping. - Signal Handling-
CTRL+Z
- converts any foreground process to background and stops it. Signal used -SIGTSTP
. no effect on the shell if no foreground process running. Implemented usingsignal()
function.CTRL+C
- Interrupts any foreground process. Signal used -SIGINT
. No effect on the shell if no foreground process running. Implemented usingsignal()
function.CTRL+D
- Closes this shell, but not the actual terminal of the computer. Implemented by considering the EOF (end of file) ASCII character.
Files | Functionality |
---|---|
cd.c | cd command |
echo.c | echo command |
history.c | history command |
ls.c | ls command |
pinfo.c | pinfo command |
repeat.c | repeat command |
pwd.c | pwd command |
jobs.c | jobs command |
sig.c | sig command |
fg.c | fg command |
bg.c | bg command |
replay.c | replay command |
baywatch.c | baywatch command |
shell_commands.c | Executing foreground/background processes, and the commands which were not implemented exclusively for this shell |
redirect.c | Implmentation of Redirection feature of the shell |
piping.c | Implmentation of Piping feature of the shell |
arrow.c | For taking input from the shell through a lower level code |
commands.h | Header file for declarations of all the commands related .c files |
prompt.c | Prompt functionality in shell |
utils.c | Various utility functions |
utils.h | Header File for declaring functions in utils.c |
main.c | The main file containing the main function for running the shell |
headers.h | Header file for declaring all global variables and including other .h files |
makefile | make instructions for compiling the code |