Simple Shell
21CSC202J - OPERATING SYSTEMS
A MINI-PROJECT REPORT
Submitted By
DARUN M [RA2311030020004]
DEEPAK R [RA2311030020005]
SYED ABDUL WAHAB [RA2311030020013
Under the guidance of
[Link]
(Assistant Professor, Department of Computer Science and Engineering)
in partial fulfilment for the award of the degree
of
BACHELOR OF TECHNOLOGY
in
COMPUTER SCIENCE AND ENGINEERING
of
FACULTY OF ENGINEERING AND TECHNOLOGY
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
RAMAPURAM, CHENNAI-600089
OCTOBER 2024
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
(Deemed to be University U/S 3 of UGC Act, 1956)
BONAFIDE CERTIFICATE
Certified that this mini project report titled “Simple Shell” is the bonafide
work of DARUN M (RA2311003020004),DEEPAK R (RA2311030020005),
SYED ABDUL WAHAB (RA2311030020013)”who carried out the project
under my supervision. Certified further, that to the best of my knowledge, the
work reported herein does not form any other project report or dissertation on
the basis of which a degree or award was conferred on an occasion on this or
any other candidate
SIGNATURE
[Link] ,
Assistant Professor,
Computer Science and Engineering, SRM
Institute of Science and Technology,
Ramapuram, Chennai.
ii
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
RAMAPURAM, CHENNAI -600089
DECLARATION
We hereby declare that the entire work contained in this mini project report
titled “Simple Shell” has been carried out of DARUN M
(RA2311003020004), DEEPAK R (RA2311030020005), SYED ABDUL
WAHAB (RA2311030020013) at SRM Institute of Science and Technology,
Ramapuram, Chennai - 600089,
Place: Chennai
Date:
iii
ABSTRACT
This project presents the design and implementation of a
simple shell program for Unix-like operating systems. The
shell serves as a command-line interface that allows users to
interact with the operating system by executing commands,
managing processes, and handling input/output redirection.
Key features of the shell include support for basic command
execution, piping, and background processes. The program
parses user input, identifies built-in commands, and invokes
external executables while managing system calls effectively.
This shell also incorporates error handling to provide
feedback on invalid commands. Through this project, we aim
to illustrate the fundamental principles of operating system
interaction, process management, and user interface design in
a straightforward manner. The resulting shell serves as a
learning tool for understanding the core functionalities of
more complex shells and the underlying mechanics of
command execution in operating systems
iv
TABLE OF CONTENTS
Chapter No. Title Page No.
ABSRACT iv
LIST OF FIGURE
1 INTRODUCTION 1
1.1 Overview 1
1.2 Problem Statement 2
1.3 Objective of the Project 2
1.4 Scope of the Project 2
2 SOFTWARE AND HARDWARE 3
2.1 Hardware Requirements 3
2.2 Software Requirements 4
3 PROJECT DESCRIPTION 5
3.1 Introduction 5
3.2 Algorithm Used 8
3.3 Advantages of Algorithm used 9
3.4 Architecture 10
3.5 Explanation of the Project 13
4 RESULT 14
v
4.1 Source Code 15
4.2 Compilation 21
4.3 Output 22
5 CONCLUSION 22
6 REFERENCE 23
LIST OF FIGURES
Fig No. Figure Name Page No.
4.1 Compilation 21
4.2 Output 22
vi
CHAPTER 1
INTRODUCTION
1.1 Overview
The Simple Shell Program project focuses on developing a basic command-line
interface (CLI) for Unix-like operating systems, mirroring essential functionalities
found in more advanced shells such as Bash. The shell serves as a bridge between the
user and the operating system, allowing for efficient command execution, process
management, and the utilization of features such as input/output redirection and
piping.
Central to this project is the command parsing component, which analyzes user input
to identify commands and their associated arguments. This involves recognizing both
built-in commands (like `cd` and `exit`) and external executables, facilitating a
versatile user experience. Process management is another critical aspect, where the
program employs system calls like `fork()` to create new processes and `exec()` to
execute commands, thereby managing foreground and background processes
seamlessly.
The shell also supports input and output redirection, enabling users to redirect data
between files and commands using operators like `>` and `<`. Additionally, the piping
feature allows users to link multiple commands together, where the output of one
command can directly serve as the input for another. This capability empowers users
to create more complex command sequences effortlessly.
Error handling is an integral part of the shell’s functionality, ensuring that users receive
informative feedback for invalid commands and exceptions during execution. The
interactive nature of the shell allows it to continuously accept input until the user
decides to exit, fostering a dynamic and engaging environment.
Overall, this project serves as an educational tool, helping users grasp fundamental
concepts of operating systems, including process management and command
execution. By working on the Simple Shell Program, users gain valuable hands-on
experience with system calls, string manipulation, and user interface design, laying a
solid foundation for exploring more sophisticated command-line interfaces in the
future.
1.2 Problem Statement
The goal of this project is to develop a simple shell program for Unix-like operating
systems that allows users to interact with the system via a command-line interface.
This shell will enable users to execute commands, manage processes, and utilize
essential features such as input/output redirection and piping. By implementing this
shell, users will gain hands-on experience with key operating system concepts,
including process creation and management, command parsing, and error handling.
Ultimately, the project aims to provide a foundational understanding of how
command-line interfaces function and prepare users for exploring more advanced
shell functionalities and operating system principles.
1.3 Aim of the Project
The aim of the Simple Shell Program project is to create a basic command-line
interface for Unix-like operating systems, enabling users to execute commands and
manage processes effectively. It seeks to implement core features like command
parsing, process management, and input/output redirection while enhancing user
interaction. The project aims to deepen understanding of fundamental operating
system concepts, preparing users for more advanced topics and encouraging
exploration within command-line environments. Ultimately, it aspires to provide a
practical learning experience that equips users with essential skills and knowledge for
further studies in operating systems and software development.
1.4 Scope of the Project
The scope of the Simple Shell Program project encompasses the following key areas:
1. Command Execution: Implementation of basic command execution for both
built-in commands (e.g., `cd`, `exit`) and external executables, allowing users to
interact with the operating system.
2. Process Management: Utilization of system calls to manage foreground and
background processes, including creating, terminating, and controlling process
execution.
3. Input/Output Redirection: Support for redirecting input and output streams
using standard operators (e.g., `>`, `<`), enabling users to manipulate data flow
between commands and files.
2
4. Piping: Implementation of command piping to allow users to chain multiple
commands, facilitating more complex data processing through sequential execution.
5. User Interface: Creation of a simple yet effective command-line prompt that
encourages user interaction and provides a responsive environment for command
input.
6. Extensibility: Designing the shell with the potential for future enhancements,
such as support for additional features (e.g., history, aliases) and improved user
interface options.
By addressing these areas, the project aims to provide a comprehensive
understanding of shell functionality and the underlying mechanics of operating
systems, laying a foundation for more advanced explorations in software
development and system design.
CHAPTER 2
SOFTWARE AND HARDWARE SPECIFICATIONS
2.1 Hardware Requirements
The equipment prerequisites for this venture are as takes after:
• Processor: Intel Core i3 or equivalent (Intel Core i5 or equivalent for better
performance)
• Ethernet association (LAN) OR a remote connector (Wi-Fi)
• Difficult Drive: Least 100 GB; Suggested 200 GB or more
3
• Memory (RAM): 4 GB RAM (8 GB RAM or more, especially for multitasking)
2.2 Software Requirements
The program prerequisites for this venture are as takes after:
Operating System:
Compatible with Windows, macOS, or Linux distributions
(Ubuntu, Fedora, etc.)
• Development Environment:
• C/C++ Compiler (e.g., GCC for Linux, MinGW for Windows)
• Integrated Development Environment (IDE) (e.g., Code::Blocks, Visual
Studio, or any text editor)
• Libraries:
Standard C libraries (usually included with the compiler)
• Additional Tools (Optional):
• Version control software (e.g., Git) for managing project versions
Debugging tools to assist in troubleshooting the program
4
CHAPTER 3
PROJECT DESCRIPTION
3.1 Introduction
The Simple Shell project involves the development of a basic command-line shell that
enables users to execute commands, manage input/output redirection, and handle
background processes, providing a practical introduction to key operating system
concepts. At its core, this shell will mimic fundamental functionalities of more
sophisticated shells like Bash, allowing users to interact with the operating system
through textual commands. The primary objective is to create an environment where
users can input commands, which the shell will parse and execute while managing
associated processes effectively. The implementation begins with command parsing,
where the shell reads user input and tokenizes it into meaningful components—
commands and their respective arguments. This parsing is crucial for correctly
identifying and executing the specified tasks. Users can execute both built-in
commands, such as `cd` (change directory) and `exit` (terminate the shell session), as
well as external commands located within the system's PATH. For instance, when a
user types a command, the shell uses system calls like `fork()` to create a new process;
the parent process manages the shell's prompt while the child process executes the
command. If the command is a foreground process, the shell waits for its completion
before accepting further input, whereas background processes allow the shell to remain
responsive to user commands without blocking.
Another significant feature of the Simple Shell is its ability to handle input and output
redirection, which is achieved through standard operators like `>` and `<`. This
capability enables users to redirect the output of a command to a file or to take input
from a file, enhancing the shell’s versatility. For example, using `command >
[Link]` allows users to write the command’s output directly to a file, while
`command < [Link]` enables the command to read from a specified file. The shell
will manage file descriptors appropriately to ensure these operations work smoothly.
In addition to redirection, the shell will also support piping, allowing users to connect
multiple commands together using the `|` operator. This feature facilitates complex
data processing by enabling the output of one command to serve as the input for
another. For example, a user might execute a sequence like `ls | grep ".txt"`, where the
output of the `ls` command is filtered through the `grep` command to display only text
5
files. Implementing piping requires careful management of processes and file
descriptors to ensure data flows correctly between commands.
Error handling is a critical aspect of the Simple Shell's design, aiming to provide clear
and informative feedback to users. The shell will implement mechanisms to detect
invalid commands, unsuccessful executions, and issues with input/output redirection
or piping. For example, if a user tries to execute a non-existent command, the shell
will respond with an appropriate error message, helping users understand what went
wrong. Similarly, if there are problems with file access during redirection, the shell
will notify the user of the issue. This focus on user feedback is essential for creating a
user-friendly experience and encourages exploration and experimentation within the
shell environment. The user interface will be straightforward, displaying a prompt that
continuously awaits user input until the user decides to terminate the session by issuing
the `exit` command. The design will ensure that the shell remains responsive, allowing
users to input commands without significant delays.
The implementation will be organized into several modular components, each
responsible for specific functionalities. Key files in the project will include `main.c`,
which manages the main loop and user interactions; `parser.c`, responsible for
command parsing and tokenization; `executor.c`, which handles the execution of
commands and process management; `redirect.c`, implementing input/output
redirection; `pipe.c`, facilitating the piping of commands; and `builtin.c`, which
defines the functionality of built-in commands. This modular approach will enhance
code organization, making it easier to manage and extend the shell’s capabilities. The
development process will begin with setting up a Unix-like environment that includes
a compatible C compiler, such as GCC, and a suitable text editor or integrated
development environment (IDE) for coding. Once the environment is established, the
focus will shift to implementing the command parsing logic, where a tokenizer
function will split user input into tokens based on whitespace and special characters.
Following parsing, the shell will execute commands using the `fork()` and `exec()`
family of system calls. The `fork()` function creates a new child process for executing
the command, while the parent process waits for the child to finish if it is a foreground
process. If the command is intended to run in the background, the shell will continue
6
accepting input without waiting for the command to complete. The execution logic
will utilize `execvp()` for running external commands, ensuring that the shell can
locate and execute the appropriate executables specified in the user input. The redirect
functionality will involve managing file descriptors using the `dup2()` system call,
which allows the shell to redirect standard input and output to and from files as
specified by the user. The piping feature will require creating a pipe using the `pipe()`
system call and managing the data flow between commands effectively.
Testing will play a crucial role in the development of the Simple Shell Program,
ensuring that it operates reliably and meets user expectations. The testing strategy will
include unit testing, where individual components are tested for correctness, followed
by integration testing to assess how well the components work together. User
acceptance testing will also be conducted to gather feedback on usability and
functionality, allowing for further refinements. Performance testing will evaluate how
the shell handles various scenarios, such as executing multiple commands, managing
large files, and maintaining responsiveness during background process execution.
While the initial scope of the project is focused on delivering a functional command-
line shell, several potential enhancements can be considered for future development.
These enhancements could include implementing a command history feature, allowing
users to recall previously entered commands with ease. Additionally, the ability to
create aliases for frequently used commands could streamline user interaction.
Implementing tab completion for commands and filenames would also improve the
user experience by minimizing typing errors. Furthermore, enabling the execution of
shell scripts would allow users to automate tasks by grouping commands into script
files. Enhanced error reporting could also be developed to provide more detailed
feedback and suggestions for corrective actions, further improving usability.
In conclusion, the Simple Shell project represents a comprehensive effort to build a
basic command-line interface that encapsulates essential functionalities of Unix-like
operating systems. By implementing key features such as command execution, process
management, input/output redirection, and piping, the project serves both as a practical
tool for system interaction and an educational resource for understanding operating
system principles. Users engaging with this shell will gain valuable hands-on
7
experience, equipping them with essential skills for further exploration in software
development and systems programming. The focus on user interaction, error handling,
and robust testing aims to deliver a reliable and intuitive command-line experience
while laying the groundwork for potential future enhancements that can further enrich
its functionality. Ultimately, this project aspires to foster a deeper understanding of
command-line interfaces and the underlying mechanics of operating systems, paving
the way for more advanced studies and applications in the field of computing.
3.2 Algorithm Used
1. Command Parsing Algorithm
• Input Reading: Read the entire line of input using functions like `fgets()`.
• Tokenization: Use `strtok()` to split the input string into tokens (commands
and arguments) based on spaces and special characters (like `>`, `<`, and `&`).
• Background Process Detection: Check if the last token is `&` to determine if
the command should run in the background.
• Redirection Detection: Look for the `>` and `<` symbols to identify output and
input redirection. Adjust the token parsing accordingly to capture file names.
2. Process Creation Algorithm
• Forking Process: Use `fork()` to create a child process. The parent process can
either wait for the child to complete or continue executing (if in the
background).
• Error Handling: Check if `fork()` returns a negative value to handle errors in
process creation.
3. Command Execution Algorithm
• File Descriptor Management: If redirection is specified, use `open()` to get file
descriptors for input and output files. Use `dup2()` to redirect standard
input/output to these file descriptors.
• Executing Commands: Use `execvp()` in the child process to replace the process
image with the command to be executed.
4. Background Process Management Algorithm
8
• Non-blocking Wait: If the command is to run in the background, do not call
`waitpid()` immediately. Instead, simply return control to the shell for further
commands.
• Process Monitoring: Optionally, you could implement a mechanism to
periodically check for background process completion.
5. Error Handling Algorithm
• Validation: Before executing commands, validate the parsed arguments and
check for file access permissions for redirection.
• Error Reporting: Use `perror()` to print error messages related to system calls
(like `execvp()`, `fork()`, `open()`, etc.).
3.3 Advantage of Algorithm used
1. Modular Design
• Separation of Concerns: By dividing the shell into distinct modules (command
parsing, process management, execution, etc.), the code becomes easier to
manage, understand, and maintain. Each module can be developed and tested
independently.
2. Efficiency
• Forking Mechanism: The use of fork() allows for efficient process creation,
enabling the shell to handle multiple commands concurrently without
significant overhead.
• Non-blocking Execution: Background process management allows users to run
multiple commands simultaneously, improving responsiveness and user
experience.
3. Flexibility
• Command Parsing: The parsing algorithm accommodates various command
formats, including options and arguments. This flexibility allows users to input
complex commands easily.
9
• Redirection Support: By handling input/output redirection, the shell can
interface with files, enhancing its functionality beyond simple command
execution.
4. Robustness
• Error Handling: Integrating error handling mechanisms, such as checking the
success of system calls (like fork() and execvp()), ensures that the shell can
gracefully handle issues without crashing, providing meaningful feedback to
users.
5. User-Friendly Features
• Background Execution: Allowing commands to run in the background helps
users multitask, improving the overall command-line experience.
• Output Management: Clear output display and error reporting help users
understand command results and troubleshoot issues effectively.
3.4 Architecture
The architecture of the Simple Shell project is designed to facilitate modularity,
maintainability, and scalability, allowing for clear separation of concerns. This
structure enhances the shell's functionality and provides a robust framework for
implementing core features such as command execution, input/output redirection,
and process management. Below is an overview of the architectural components and
their interactions.
1. Main Components
The architecture consists of several key components, each responsible for specific
functionalities:
Main Loop (main.c): The entry point of the shell. It manages the interactive
command prompt, handles user input, and initiates the command processing pipeline.
10
Command Parser (parser.c): Responsible for parsing user input, breaking it down
into tokens that represent commands and their arguments. This component identifies
built-in commands, external commands, and special operators (e.g., piping and
redirection).
Command Executor (executor.c): Manages the execution of commands. It uses
system calls like `fork()` to create new processes and `execvp()` to run external
commands. It also manages foreground and background processes.
Input/Output Redirection (redirect.c): Implements the logic for redirecting input
and output streams using file descriptors. This component handles operators like `>`
for output redirection and `<` for input redirection.
Piping (pipe.c): Facilitates the piping of commands by creating a communication
channel (pipe) between processes. This component ensures that the output of one
command can be used as the input for another.
Built-in Commands (builtin.c): Contains the logic for handling built-in commands,
such as `cd`, `exit`, and `help`. This component allows the shell to perform
operations that don't require external executables.
Error Handling (error.c): Centralized error management that provides feedback to
users regarding invalid commands, execution failures, and issues related to
redirection and piping.
2. Data Flow
1. User Input: The shell prompts the user for input through the command line.
2. Parsing: Once the user submits a command, the `main.c` invokes the parser in
`parser.c` to tokenize the input.
3. Execution: The parsed tokens are sent to the executor in `executor.c`, which
determines if the command is built-in or external.
• Built-in Command: If the command is built-in, the executor calls the
corresponding function from `builtin.c`.
• External Command: If the command is external, the executor forks a new
process and calls the appropriate `execvp()` function to execute it.
11
4. Redirection and Piping: Before executing commands, the executor checks for
any redirection or piping requirements. If present, it invokes `redirect.c` to set up
file descriptors or `pipe.c` to establish communication between processes.
5. Process Management: The executor handles process management by waiting
for foreground processes to complete or continuing with background processes.
6. Error Handling: Throughout the process, the error handling component
(`error.c`) monitors for issues and provides user feedback when necessary.
3. Flow Diagram
1. Start
2. Display Prompt
3. Get User Input
4. Parse Input → [tokens created]
5. Identify Command Type
• Built-in Command → Execute from `builtin.c`
• External Command → Fork Process → Execute from `executor.c`
6. Check for Redirection/Piping
• Redirect Input/Output → Use `redirect.c`
• Pipe Commands → Use `pipe.c`
7. Manage Processes
• Foreground: Wait for completion
• Background: Continue accepting input
8. Error Handling → Monitor and report issues
9. Repeat or Exit
10. End
4. Error Handling Architecture
12
• The error handling system will be integrated throughout the shell components,
ensuring that errors are caught and reported effectively. The flow of error
handling can be visualized as follows:
• Errors during parsing: If the input cannot be parsed correctly, the parser returns
an error code, which the main loop uses to inform the user.
• Execution errors: If an external command fails to execute (e.g., command not
found), the executor will call the error handling function, which will print an
informative message.
• Redirection errors: If file access fails during input/output redirection, the
redirection component will trigger error handling to report the issue.
5. Modularity and Scalability
The modular design of the Simple Shell allows each component to be developed,
tested, and maintained independently. This separation facilitates scalability, as new
features (like command history or aliases) can be integrated by adding new modules
without disrupting existing functionality. Future enhancements could include:
• Command History: A module to track and recall previous commands.
• Aliases: A module that allows users to create shortcuts for commands.
• Scripting Support: A module for executing script files, enhancing the shell's
capabilities.
3.5 Explanation of Project
Purpose
The Simple Shell project aims to develop a basic command-line interface for
Unix-like operating systems, allowing users to interact with the system through
text-based commands. It serves as a practical tool for executing commands,
managing processes, and understanding fundamental operating system concepts.
Additionally, it provides a foundation for users to explore more advanced features
and functionalities commonly found in sophisticated shells.
Key Components 1. Command Parser:Tokenizes user input into commands
and arguments, facilitating effective processing.
13
2. Command Executor:Manages the execution of commands using system calls
like `fork()` for process creation and `execvp()` for running external commands.
3. Input/Output Redirection:
Implements file redirection using operators like `>` and `<`, allowing users to
send output to files or take input from files.
4. Piping:
Supports command piping using the `|` operator, enabling the output of one
command to serve as the input for another.
5. Built-in Commands:
Includes essential commands such as `cd` and `exit`, allowing users to navigate
directories and terminate the shell session.
User Interaction
Users interact with the Simple Shell through a command-line interface that
displays a prompt, awaiting input. Upon entering a command, the shell parses the
input, executes the specified command, and displays the output or error messages.
Users can take advantage of features like input/output redirection and piping to
manipulate data streams effectively. The shell continues to prompt for input until
the user issues the `exit` command, allowing for an intuitive and responsive
experience
Chapter 4
Result
14
4.1 Source code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/wait.h>
#define MAX_LINE 1024
#define MAX_ARGS 128
void parse_command(char *cmd, char **argv) {
while (*cmd != '\0') {
while (*cmd == ' ' || *cmd == '\t' || *cmd == '\n') {
*cmd++ = '\0';
*argv++ = cmd;
while (*cmd != '\0' && *cmd != ' ' && *cmd != '\t' && *cmd != '\n') {
cmd++;
15
*argv = '\0';
void execute_command(char **argv) {
pid_t pid;
int status;
if ((pid = fork()) < 0) {
perror("Forking child process failed");
exit(1);
} else if (pid == 0) { // Child process
if (execvp(*argv, argv) < 0) {
perror("Exec failed");
exit(1);
} else { // Parent process
while (wait(&status) != pid);
int main() {
char cmd[MAX_LINE];
16
char *argv[MAX_ARGS];
int should_run = 1;
while (should_run) {
printf("myshell> ");
fgets(cmd, MAX_LINE, stdin);
if (cmd[strlen(cmd) - 1] == '\n') {
cmd[strlen(cmd) - 1] = '\0';
parse_command(cmd, argv);
if (strcmp(argv[0], "exit") == 0) {
should_run = 0;
} else if (strcmp(argv[0], "pwd") == 0) {
char cwd[MAX_LINE];
if (getcwd(cwd, sizeof(cwd)) != NULL) {
printf("%s\n", cwd);
} else {
perror("getcwd() error");
17
} else if (strcmp(argv[0], "cd") == 0) {
if (argv[1] == NULL) {
fprintf(stderr, "cd: expected argument to \"cd\"\n");
} else {
if (chdir(argv[1]) != 0) {
perror("cd failed");
} else {
int i = 0;
int fd;
int is_redirect = 0;
int is_pipe = 0;
char *cmd1[MAX_ARGS];
char *cmd2[MAX_ARGS];
while (argv[i] != NULL) {
if (strcmp(argv[i], ">") == 0) {
is_redirect = 1;
argv[i] = NULL;
cmd1[i] = NULL;
fd = open(argv[i+1], O_WRONLY | O_CREAT | O_TRUNC, 0644);
18
break;
} else if (strcmp(argv[i], "|") == 0) {
is_pipe = 1;
argv[i] = NULL;
cmd1[i] = NULL;
int j = 0;
while (argv[i + 1 + j] != NULL) {
cmd2[j] = argv[i + 1 + j];
j++;
cmd2[j] = NULL;
break;
cmd1[i] = argv[i];
i++;
if (is_redirect) {
if (fork() == 0) {
dup2(fd, 1);
close(fd);
execvp(cmd1[0], cmd1);
19
perror("Exec failed");
close(fd);
wait(NULL);
} else if (is_pipe) {
int pipefd[2];
pipe(pipefd);
if (fork() == 0) {
dup2(pipefd[1], 1);
close(pipefd[0]);
close(pipefd[1]);
execvp(cmd1[0], cmd1);
perror("Exec failed");
if (fork() == 0) {
dup2(pipefd[0], 0);
close(pipefd[0]);
close(pipefd[1]);
execvp(cmd2[0], cmd2);
perror("Exec failed");
20
}
close(pipefd[0]);
close(pipefd[1]);
wait(NULL);
wait(NULL);
} else {
execute_command(argv);
return 0;
4.2 Compilation
21
During the compilation process, the source code is saved as a ".c" file on
desktop in a Linux operating system. The "cd" command is used to navigate to
the desktop directory in the terminal. To compile the source code, the "gcc"
command is executed. If the compilation is successful, the process proceeds to
the next step. If errors occur, they are displayed in the terminal. After correcting
the errors, the compilation process is repeated until successful, allowing progress
to the subsequent steps.
4.3Output
CHAPTER 5
CONCLUSION
Creating a simple command-line shell is an insightful exercise that deepens
understanding of process management, input/output redirection, and command
execution in operating systems. Throughout the development process, we explored
essential concepts such as forking processes, executing commands with `execvp()`,
and handling both foreground and background processes. By implementing features
like input/output redirection and parsing commands, we learned how these
fundamental elements interact to form a functioning shell environment.
22
This basic shell not only demonstrates the core mechanics of command execution but
also provides a platform for further enhancements, such as adding support for piping,
built-in commands, and more robust error handling. As you continue to build on this
foundation, you can explore advanced topics like signal handling, job control, and
process synchronization. Ultimately, developing a simple shell fosters a deeper
appreciation for the complexities of operating systems and their interaction with user
commands, equipping you with practical skills that can be applied to more
sophisticated projects. Embracing these challenges will enhance your programming
proficiency and provide a richer understanding of the underlying principles that govern
shell environments.
REFERENCE
1. Making your own Linux Shell in C - GeeksforGeeks
2. Introduction to Linux Shell and Shell Scripting - GeeksforGeeks
3. Building Your Own Shell with C. Building Your Own Shell with C | by Levon
Petrosyan | Medium
23