g-Shell is a simple UNIX shell implementation written in C language. The shell provides a simple and efficient command line interface for users to interact with the operating system. The implementation of gShell includes built-in commands and the ability to run external programs.
The gShell code consists of several functions, including a parser, handler, cd_command, export_command, echo_command, and main.
The parser function takes a command entered by the user and parses it into an array of arguments that can be passed to other functions. The maximum number of arguments allowed in the terminal is 10.
The handler function is responsible for handling SIGCHLD signals generated by the child process when it terminates. The parent process removes the process that initiated the signal from the processes table. In case of a zombie process, this method is responsible for reaping it.
The cd_command function is a built-in command for handling user commands to navigate between different directories. The function allows the user to navigate to the home directory, navigate up one level, or navigate to the previous directory.
The export_command function is a built-in command for defining environment variables and using them in child processes.
The echo_command function is a built-in command for printing the input line as a string of text or the value of a defined environment variable.
The main function is responsible for handling user input, parsing the command, and executing it. The main function also handles the built-in commands.
Implemented using c language along with unistd ans sys libraries
The following table shows the current set of commands supported by the shell:
Command | Arguments | Description |
---|---|---|
cd | '', ~, /, .., - | Changes the current working directory |
pwd | None | Writes to standard output the full path name of your current directory (from the root directory) |
ls | ~, /, .., -, -l, -sl, -R, -a | Displays the contents of a directory |
mkdir | Directory name | Creates a new directory in the Linux/Unix operating system |
rm | Directory name, -r | Deletes file or directory |
ps | aux, eaf | views information related with the processes on a system |
kill | -, -s, -p | Sends the specified signal to the specified processes or process groups |
export | Expression | Marks variables and functions to be passed to child processes |
find | -H, -L Path | locates files based on some user-specified criteria |
echo | $Variable | Displays a line of string that is passed as the arguments or value of an environment variable |
Process name | & | Runs the process as a backgroud process |
- https://www.geeksforgeeks.org/create-processes-with-fork-in-cpp/
- https://stackoverflow.com/questions/19099663/how-to-correctly-use-fork-exec-wait
- https://stackoverflow.com/questions/67251953/implement-cd-command-in-c
- https://stackoverflow.com/questions/17929414/how-to-use-setenv-to-export-a-variable-in-c
- http://www.microhowto.info/howto/reap_zombie_processes_using_a_sigchld_handler.html
- https://www.geeksforgeeks.org/zombie-processes-prevention/
- https://linuxhint.com/find-kill-zombie-process-linux/