ASH (or the A-SHell) is a simple shell written in C, similar to bash. It supports several functionalities, including I/O redirection, piping, job control and many bash commands.
baywatch: A modified version of the bash command watch, that works for three specific commands:
-
interrupt: Prints the number of times the CPUs have been interrupted by the keyboard controller (i8042 with IRQ 1)
-
newborn: Prints the PID of the most recently created process.
-
dirty: Prints the size of the part of memory that is dirty.
baywatch -n <interval> interrupt
baywatch -n <interval> newborn
baywatch -n <interval> dirtyPress Q to terminate the command.
bg: Changes the state of a stopped background job to running.
bg <job_number>cd: Changes the working directory of the shell.
cd
cd - # To go to the previous working directory
cd ~
cd ../..
cd dir_1/dir_2/dir_3echo: Prints the text following "echo" on the terminal.
echo "Hello World"
echo Welcome to ASHfg: Brings the running/stopped background job to the foreground.
fg <job_number>history: Displays a list of the commands previously used (at most the 20 latest commands).
history
history <n> # To display last n commands usedjobs: Prints a list of all currently running background processes spawned by the shell in alphabetical order of the command name, along with the job number, process ID and the state.
jobs
jobs -s
jobs -r
jobs -rs
jobs -s -rls: Lists the contents of a particular directory.
ls
ls -a
ls -l
ls -al
ls -la
ls -a -l
ls -l -a
ls ../../dir_1/dir_2
ls ~
ls dir_1/file_namepinfo: Displays information about a particular process.
pinfo # Displays information about the shell process itself
pinfo <pid>pwd: Prints the absolute path of the current working directory.
pwdrepeat: Executes a given command n times.
repeat <n> <command>replay: Executes a particular command in fixed time interval for a certain period.
replay -command <command> -interval <interval> -period <period>sig: Sends the signal corresponding to signal number to the process with the particular job number.
sig <job_number> <signal_number>
- System Commands: ASH should run many of the processes that bash can, including
gedit,vim,clear, etc.
gedit
vim
clear
ps- Background Processes: Add
&at the end of the command to run it as a background process. This however only works for system commands, and not shell built-ins.
gedit &- Arrow Keys: Acts as a shortcut to easily view previous commands, and execute them, just like in bash.
UP - View earlier commands
DOWN - View more recent commands
- Run the following to generate the executable from the makefile.
make- To start the shell, run the following command.
./shell- To exit the shell, run the following command within the shell.
exitASH
|______README.md
|______makefile
|______src
|______main.c
|______utilities.c
|______header_files
| |______commands.h
| |______util_variables.h
| |______utilities.h
|
|______commands
|______arrow.c
|______baywatch.c
|______bg.c
|______cd.c
|______echo.c
|______execute.c
|______fg.c
|______history.c
|______jobs.c
|______ls.c
|______pinfo.c
|______pwd.c
|______replay.c
|______signal.c
|______terminal.c
-
main.c: Contains the main() function where execution starts. -
utilities.c: Contains utility functions that are either used for input processing or performing general tasks. Also contains the implementation of therepeatcommand and the code taking care of piping.
-
commands.h: Contains the declarations of all the functions present in thecommandsfolder. -
util_variables.h: Contains macros and important global variables used throughout the program. -
utilities.h: Contains the declarations of all the functions present inutilities.c.
-
arrow.c: Contains the implementation of the arrow key handling, which shows previous commands. -
baywatch.c: Contains the functions required for the implementation of the baywatch command. -
bg.c: Contains the implementation of the bg command. -
cd.c: Contains the functions required to change the working directory. -
echo.c: Contains the implementation of the echo command. -
execute.c: Contains the central function that takes care of command execution, as well as the code taking care of I/O redirection. -
fg.c: Contains the implementation of the fg command. -
history.c: Contains the functions required to display the history of commands used. -
jobs.c: Contains the functions necessary to list the background jobs. -
ls.c: Contains the functions required to list the contents of a directory. -
pinfo.c: Contains the functions required to display information about a particular process. -
pwd.c: Contains the implementation for the pwd command. -
replay.c: Contains the implementation of the replay command. -
signal.c: Contains the implementation of the sig command, as well as the signal handlers used. -
terminal.c: Contains the functions required to modify and obtain terminal attributes.
-
Ctrl + Z moves the foreground process to the background and stops it by sending it a SIGTSTP signal.
-
Ctrl + C interrupts the foreground process by sending it a SIGINT signal.
-
Ctrl + D logs you out of the shell.
-
6 months is exactly equal to 15778463 seconds.
-
By the process name supposed to be printed when a background process exits abnormally, we mean the name of the command used to run that background process.
-
If multiple files are given to the input/output redirection operators, the last one is considered.