PTSH
This is a basic shell written using C.
Running the code:
1.cd
to the directory the shell is present in.
2.Type the command make
.
3.Enter ./a.out
to run the shell.
Code:
-
main.c
is the file which runsrunShell()
and is the source file.runShell()
handles the inputs of the prompt and calls the necessary functions based on the command input. -
prompt.c
is solely responsible for displaying the prompt. It callsprintPrompt()
. -
cd.c
behaves as the cd function. It implements thechdir()
function. -
utils.c
contains theecho
andpwd
functions.echo
simply prints the input given.pwd
callsgetcwd
to output the absolute path of the curent directory. -
ls.c
behaves as the ls function. It also handles the-l -a -al/la
flags. It calls thescandir()
function to enlist the files in the directory. To handle the-l
flag,stat()
command is used to obtain the required data of the file. -
pinfo.c
prints the current process information. It reads the data at the/proc/pid/status
and/proc/pid/exe
to get the necessary information. -
exec.c
uses thewait()
andfork()
processes to run background and foreground processes. It also callswaitpid()
andsignal()
for detecting when a process and ended and uses flags to check if it has ended normally. -
nwatch.c
read the data at the/proc/meminfo
and/proc/interrupts
to get the data. It checks whether the user has entered a character by using thegetchar()
command. -
history.c
writes the commands entered in a file and reads them when thehistory()
function is called. -
Makefile
defines the compilation rules so that multiplegcc
s don't have to be called each time.