A shell with basic functionalities with io redirections and piping support.
It can run system commands ,both in foreground and in background.
For compiling the shell run
foo@bar>./make
for running it
foo@bar>./shell
echo
cd
pwd
pinfo
ls
, with -a , -l flags supportedexit
,quit
setenv
unsetenv
jobs
fg
bg
kjob
overkill
- Doesen't support quoting arguments or whitespace escape.
Basic functionalities of shell and how processes execute
Expisure to new system calls and library functions
Modular coding
Understanding how io, redirections and piping works
- End the input with NULL if using malloc to avoid random chars in buffer, or simply use calloc.
- Not to run certain builtin commands as child processes, example: cd when run as child , it changes directory and exits, but parent ends up remaining in the same directory.
- Not to allocate strings pointers directly for a variable, we can end up messing up the orginal string, so make a duplicate of it by strdup() or strcpy()
- While implementing ctrl-z when the process stopped, i tried send the child process to new group by setpgid(pid,0), but it gave permission error;
Fix: Irrespective of whether bg of fg process, i sent the child to new group, if it is an fg ,in the parent interface it with terminal's io by tcsetpgrp(0, pid);
-
cykshell.h
: the header file having main libraries, global constants , variables and functions. -
shell.c
: main() function; -
interface.c
: functions related to interfaceinit()
: initialises the terminal,
prompt()
: displays prompt in the terminal ,
cwd_func()
: stores current working directory shortened and previous directory
inputt()
: takes in input splits it into commands
cmd_in()
: takes in command splits into arguments
stringseperator()
: takes a string and return array of strings splitted with delimter -
cmd_exec.c
: Command execution takes placecmd_exec()
: takes in arguments of a command and executes it.
buitlin_exec()
: executes builtin commands.
bg_check()
: check if it is a bg process.
bg_end()
: display if background process ends.delbg()
to get process name of pid and delete if neccesary. -
colours.c
: just storing few colour functions -
builtin.c
: few small builtin functions pwd_b() cd_b() echo_b() exit_b() -
ls_exec.c
: ls command by ls_exec() function -
pinfo_exec
: pinfo command by pinfo_exec() function -
ioredir.c
: ioredir() function for redirections. -
pipe.c
: for piping the commands -
killakill.c
: kjob and overkill implementation. -
jobsrelated.c
: jobs , fg and bg implementation -
signalhandler.c
: signal handling for ctrl-c and ctrl-z
Assignment 3 bonus: cd -
(P.S: The code was compiled in arch distro, it wasnt compiling unless -fcommon was used, if it doesent compile, pls use appropriate flags in makefile and try again.
Thank you)