Skip to content

An interactive user defined bash-like Shell which supports semicolon separated list of commands. Implemented in C, supports I/O redirection, piping, process management and signal handling.

Notifications You must be signed in to change notification settings

chandan-shrivastava/cshell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C-Shell

To compile the shell, run:

make

After compilation, to start the shell run:

./c-shell

This is the main file for the shell's execution. On execution the shell clears the terminal for smooth execution. It sets up the Home Directory. The history is loaded at this point, and the main while loop is activated, waiting for human interaction. It is also responsible to handle white spaces sepearated commands. If there are several instructions on a single line, the ; is used to separate them and call execution for each of them. It also handles the execution of background process when it exits.

This file contains all the libraries needed for the execution of the shell. It also contains all the global variables used throughout the running of the shell.

This file handles the excution of all the commands. The commands are checked with the arguments and executed as per the need.

This file contains the implementation of the cd command used to change directories. Usage:

cd ../
cd -
cd *dirname*

This file contains the implementation of the echo command used to print text on the shell. Usage:

echo *text*

This file contains the implementation of the pwd command used to get the current working directory. Usage:

pwd

This file contains the implementation of the ls command used to get the contents of a directory. It handles two types of flags: -a and -l have also been implemented. The falgs can be in any order. It can also show the contents of various directories given as its arguments. If the file is more than 6 months old then ls -l changes the modified time to year. Usage:

ls
ls *flags*
ls *flags* *dir*

This file contains the implementation of the user defined pinfo command which can be used to get the process information of the current process by default or a process specified by its pid which is given as argument. This command shows the pid specified, Process status whether it is running, sleeping, zombine or stopped. The status has a + if the process is running in foreground. It also shows the Virtual memory and the executable path of the process. Usgae:

pinfo
pinfo *pid*

This file contains the implementation for the execution of foreground and background processes. Background processes can be run by placing an & at the end of the command. The variable back is set to 1 if the process is a background process or 0 if it is a foreground process. Usage:

gedit &
firefox &
vim &

This file contains the implementation of the prompt which is to be printed before any command the user enters. It showcases the username, hostname, and the current working directory.

This file contains the implementation of the history command used to display the users most recent commands. It shows the 10 most recent commands by default but the number of commands to be shown can be given as an argument. The previous session history is loaded again on start of the shell. While running the commands are stored in an array to reduce overhead of reading and writing from a file. If the last command is same as of the command entered then it is not added to the file. We do not store more than previous 90 commands. It keeps deleting oldest 10 command once excedding 90 commands.

history
history *num*

This file conatains the command bg command which is used to change status of a background process from running to stopped. Usage:

bg *job_no*

This file conatains the command fg command which is used to bring a background process into the foreground and it change its status from stopped to running if required. Usage:

fg *job_no*

This file conatains the command jobs command which displays all the current background processes with their pid and job number in increasing alphabetical order. Implemented 2 flags -r and -s respectively to show running and stopped processes respectively.Usgae:

jobs
jobs -r
jobs -s

This file conatains the command sig command which can be used to send a signal to a background process by its job number. Usage:

sig *job_no* *signal_no*

This file is used to implement the pipe functionality in the commands. Usage:

cat sig.c | wc -l > lines.txt

This file is used to implement the redirect of input/output functionality in the commands. Usage:

cat < sig.c >> sig1.c

This file contains the implementation of the signal handler to receive the SIGCHILD signal from the child background processes. After receiving the signal it determines whether the child process terminated normally and prints it to stderr along with its name, pid and status. It also includes the signal handlers for dealing with SIGINT and SIGTSTP signal related to Ctrl C and Ctrl Z.

This file contains the implementation of a linked list to store the background processes and sorting function to sort the linked list for jobs command.

This file contains the implementation of replay command which executes a particular command in fixed time interval for a certain period. YOu cannot execute another command while it is running. Usage:

replay -command *command* -interval *interval* -period *period*

This file contains the implementation of repeat command which executes a particular command multiple times at once. Usage:

repeat *no_of_times* *command* 

About

An interactive user defined bash-like Shell which supports semicolon separated list of commands. Implemented in C, supports I/O redirection, piping, process management and signal handling.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published