C-Shell is a custom shell implementation written in C. It provides a command-line interface for users to interact with the operating system. Apart from the usual bash commands, it contains various specialised commands curated specially to enhance the user experience. It can execute built-in commands, run external programs, manage processes, log commands, and provide manual pages for commands.
- When awaiting user input, a
shell promptis displayed. - Contains information like username, system name, current working directory and the last executed process.
- Allowing
multiple ";" seperated commandsto be passed in as input. - Sequentally runs the all the commands.
- An error in one not affecting subsequent runs (unless it is dependent on previous command's result).
- Custom command to
change directory. - Similar to cd but allows multiple arguments at a time.
- Supports all sorts of pathing (relative, absolute, none, special signs like "-", "~", "." and "..").
- Custom command to
show contents of a directory. - Similar to ls, with functionalities of flags like -a, -l and all their combinations.
- Supports all sorts of pathing (relative, absolute, none, special signs like "~", "." and "..").
- Provides colour-coded and structured output for enhanced user experience.
- Reveals cwd in absence of any path; and doesnt support multiple paths (yet!)
- Maintains a
log file(at systemFiles/cmndlogs.txt) of all the commands executed; which is shared across all instances of the shell. - Maintains a cap (15 lines, for demo purposes) on the file size.
- When run with the
purgeargument, it clears the log file. - Also supports
execute Ncommand to run the Nth command (fromt the end) from the log file.
- Supports all the
system commandslike ls, cat, echo, pwd, etc; along with their respective flags and arguments. - Supports running of background processes using "&" at the end of the command.
- Displays the process id of the background process, and the process name when it completes; keeping the user informed.
- Custom command to
show process details. - Takes process id as input and shows details like process ID, name, state, memory usage, etc.
- Shows C-shell's process details in absence of any pid; and doesnt support multiple paths (yet!).
- Custom command to
search for a file/directory. - Takes a filename as input and searches for it in the current directory; supports all sorts of pathing (relative, absolute, none, special signs like "~", "." and "..").
- Takes upto two arguments; first (compulsary) being the file/directory to look for and the second (optional) being the directory to search in.
- Allow users to set
custom aliases and/or functions. - Supports passing arguments to the custom commands.
- Similar to bash, supports
I/O redirectionusing > (writing), < (reading), >> (appending). - Supports
pipingusing | to pass the output of one command as input to another. - Supports multiple redirections and pipings in a single command.
- Prints the
list of processesspawned by our shell. - Shows details like process ID, name and status.
- Only shows the background processes spawned by the shell.
- Takes a pid and
pings the processwith the provided signal.
- Allows the user to
bring a background process to the foregroundusing the fg command. - Allows the user to
run a stopped background processusing the bg command.
- Displays the
process id of the most recently created processon the system. - Prints the PID every N seconds, until the key 'x' is pressed.
- Custom command to
display manual pagesfor the commands. - Takes a command name as input and extracts the manual from the Internet.
- Well, no spoilers here! You gotta find them yourself!
- Hey, don't go looking for them in the code; that's cheating!
Note : For more details, refer to this.
To start the C-Shell, follow these steps:
-
Build and Run the Shell executable using
make:make
-
(Optional, but Recommended) Clean up the build files:
make clean
-
vim &may run into some problems, as the vim window appears but the keyboard control is with the shell. Leading to the inability of the user to interact with the vim smoothly, and hence raising significant annoyance. While it may seem a very hypothetical command call to run vim in background, but just in case. -
Ctrl+Zputs thw whole shell in the background. This may be a sub-optimally designed feature, one can easily bring the shell back to the foreground using the 'fg' command. -
The
activitiescommand only shows the background processes spawned by the shell, and not all the processes spawned (the latter actually fills up the screen, in certain cases, and makes it very user-unfriendly). Also, the print is not in lexographically sorted order; but in the order of the process creation (seemed like a more user-friendly approach; and also makes it less memory-intensive for the program). Since, we are doing only background processes, a stopped status refers to a zombie process; and running otherwise. -
Ctrl+Dquits the shell gracefully, ie, it waits for all foreground processes to complete before exiting. This is a deviation from the requirements, but I believe it is a more user-friendly approach. -
As for any other bugs that you may encounter, do let us know! The code monkeys at our heaquarters are trying their best in making this shell better and better!
- CS3.301 Operating Systems and Networks (OSN) Course at IIIT-Hyderabad by Prof. Karthik Vaidhyanathan and Team.
- ChatGPT and Co-Pilot