A Shell written in C. This is a project for my Operating Systems class. The goal is to create a user-defined interactive shell program that can create and manage new processes. It will also be able to handle input/output redirection and piping, and will be able to run in the background.
It has the following features:
-
Shell Prompt
user@host:~/dir$
contains the username, hostname, and the invoking directory as the home directory. Supports full path names that are outside of the home directory. -
Built-in Commands (without using
execvp
)-
cd <dir>
: Changes the current directory to<dir>
cd
changes to the home directorycd -
changes to the previous directory
-
pwd
prints the current directory -
echo
prints the arguments -
ls [-al] <dir>
lists the contents of the directory - argumentdir
prints the contents of the directory --l
long listing format with file size, permissions, owner, group, date modified, file name and symbolic link --a
shows hidden files
-
-
External Commands (using
execvp
) with background execution (&
) and show when a background process is finished similar to bash. -
Input/Output Redirection
>
redirects the output of a command to a file<
redirects the input of a command from a file>>
appends the output of a command to a file- Shows an error if the file does not exist
-
Piping
|
pipes the output of one command to the input of another command- Supports multiple pipes
- Supports redirection with pipes
-
User defined commands
-
pinfo
prints the process id, process status, memory, and executable path of the shell or the process id given as an argument -
nightswatch [-n] <command>
Modified version ofwatch
that prints the output of the command everyn
seconds.n
is 2 seconds by default.-n
specifies the number of seconds to wait between updatescommand
can beinterrupt
ornewborn
interrupt
prints the number of interrupts CPU(s) have been interrupted by the keyboard since bootnewborn
prints the PID of the most recently created process
-
history <n>
prints the last 10 orn
commands entered by the user -
setenv <var> <value>
sets the environment variablevar
tovalue
-
unsetenv <var>
unsets the environment variablevar
-
jobs
lists all the background processes spawned by the shell and their status (running or stopped) in the order they were spawned -
kjob <job number> <signal number>
sends the signalsignal number
to the process with the job numberjob number
-
fg <job number>
brings the process with the job numberjob number
to the foreground -
bg <job number>
brings the process with the job numberjob number
to the background -
overkill
kills all the background processes spawned by the shell -
quit
exits the shell
-
-
Signal Handling
Ctrl+Z
stops the foreground processCtrl+C
kills the foreground process
-
Exit Codes in the prompt