Skip to content

A simple shell written in C, similar to bash. It supports several functionalities, including piping, redirection, job control and many bash commands.

Notifications You must be signed in to change notification settings

coniferousdyer/ASH

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ASH - The A-SHell

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.

Commands

  • baywatch: A modified version of the bash command watch, that works for three specific commands:
  1. interrupt: Prints the number of times the CPUs have been interrupted by the keyboard controller (i8042 with IRQ 1)

  2. newborn: Prints the PID of the most recently created process.

  3. dirty: Prints the size of the part of memory that is dirty.

baywatch -n <interval> interrupt
baywatch -n <interval> newborn
baywatch -n <interval> dirty

Press 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_3
  • echo: Prints the text following "echo" on the terminal.
echo "Hello World"
echo Welcome to ASH
  • fg: 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 used
  • jobs: 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 -r
  • ls: 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_name
  • pinfo: 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.
pwd
  • repeat: 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

Setup

  • 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.
exit

Directory Structure

ASH
|______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

Code Division

  • 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 the repeat command and the code taking care of piping.

Header Files

  • commands.h: Contains the declarations of all the functions present in the commands folder.

  • util_variables.h: Contains macros and important global variables used throughout the program.

  • utilities.h: Contains the declarations of all the functions present in utilities.c.

Commands

  • 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.

Signal Handling

  • 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.

Assumptions

  • 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.

About

A simple shell written in C, similar to bash. It supports several functionalities, including piping, redirection, job control and many bash commands.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published