This is a working C shell that would mimic a bash shell which supports colon seperated commands.
To start the shell use the following commands
make
./myshell
To stop the shell use the following command
exit
You can also click ctrl
+ D
This file contains all the libraries used in executing the shell. It also conatains the declarations of all functions, global variables etc.
int main()
This is the main file which contains the main function. It runs an infinite loop and on each iteration it calls other functions. It seperates the semicolon seperated commands and calls other functions to execute them
void print_prompt()
This function prints the user name, host name and the directory in which the process is running during execution in a formatted order.
void check_for_bg_process()
This function checks for any completed backgroud process and prints a statement on the terminal.
void tokenise(char *command)
This function removes the extra spaces in the obtained single command without ; from main.
void identify_command(char **arg, int num)
This function identifies which command to execute and also determines if it is one of the builtin commands or one from the functions written here. It also does the repeat
command function.
void echo_execution(char **arg, int num)
This function does the echo
command execution
void pwd_execution()
This function does the pwd
command execution.
void cd_execution(char **arg, int num)
This function does the cd
command execution. It also supports the usage of special symbols like ~, /, -, .., .
void ls_execution(char **arg, int num)
This function does the ls
execution. It also supports the usage of -l
and -a
flags individually or together. It also supports listing the files or file details of multiple directories or files together.
void background_execution(char **arg, int num)
This function implements the background and foreground process. It stores the ongoing background process in a linked list. Builtin commands are implemented using execvp()
.
void pinfo_execution(char **arg, int num)
This function does the pinfo
command execution.
void exit_execution()
When exit
command is used the shell stops. This is implemented by this function.
int redirection(int redirect, int num_args)
This function does the redirection part when >
, <
, >>
are used.
It uses dup
, dup2
functions to accomplish this.
void pipe_execution(char *pipecommand)
This function does the piping part when |
is used. It uses pipe
function to achieve this.
void jobs_execution(char **arg, int num)
This function executes the jobs
command. It gives the details of all the running and stopped processes and it also facilitates the usage of two flags -s
to display only stopped processes and -r
to display only running processes.
It searches for the status in /proc
folder.
void sig_execution(char **arg, int num)
This function does the execution of sig
command where we specify the job number and the signal to pass and it passes the given signal to the specified process.
This uses kill
function.
void fg_execution(char **arg, int num)
This function executes fg
command.
It takes a job number and brings to the foreground and makes it running if it is stopped.
This uses kill
function.
void bg_execution(char **arg, int num)
This function executes bg
command.
It takes a job number and makes it running if it is stopped.
This uses kill
function.
void ctrl_c_execution(int signum)
This function interrupts any currently running foreground job, by sending it the SIGINT signal whenever ctrl
+ C
is pressed.
void ctrl_z_execution(int signum)
This function pushes any currently running foreground job into the background, and change its state from running to stopped whenever ctrl
+ D
is pressed.
- At max there can be 64 semi-colon seperated commands in a line.
- Each individual command can have 64 arguments and each one of them can be at max 1024 characters long.
- All the paths given must be less than 1024 characters.
- The hostname, system name, current working directory path is less than 1024 characters.
- In a command involving piping there can be at max 64 piped commands.