0% found this document useful (0 votes)
8 views

Simple shell os

The document is a mini-project report on a basic command-line shell implemented in C++, designed to facilitate user interaction with the operating system. It supports foreground and background execution of commands, utilizes system calls for process management, and includes robust error handling. The project aims to provide an educational tool for understanding operating systems and encourages further exploration of shell functionalities.

Uploaded by

rdeepak2023
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Simple shell os

The document is a mini-project report on a basic command-line shell implemented in C++, designed to facilitate user interaction with the operating system. It supports foreground and background execution of commands, utilizes system calls for process management, and includes robust error handling. The project aims to provide an educational tool for understanding operating systems and encourages further exploration of shell functionalities.

Uploaded by

rdeepak2023
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 28

Simple Shell

21CSC202J - OPERATING SYSTEMS

A MINI-PROJECT REPORT

Submitted By

DARUN M [RA2311030020004]
DEEPAK R [RA2311030020005]
SYED ABDUL WAHAB [RA2311030020013]

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)”

SIGNATURE
M, M.E., (Ph.D.),

Assistant Professor,

Computer Science and Engineering,


SRM Institute of Science and Technology,
Ramapuram Campus, Chennai.

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 by DARUN
M(RA2311003020004),DEEPAK R (RA2311030020005), SYED ABDUL
WAHAB (RA2311030020013), at SRM Institute of Science and Technology,
Ramapuram Campus, Chennai - 600089,

Place: Chennai

Date:
ABSTRACT

This C program implements a minimalistic command-line shell that allows


users to execute system commands interactively, showcasing key operating
system concepts. It supports both foreground and background execution,
determined by the presence of an "&" at the end of commands, enabling users
to run multiple tasks simultaneously. The shell utilizes fork and execvp
system calls for effective process management, creating child processes for
command execution. It dynamically tokenizes user input into arguments
while ensuring safe handling with null-terminated strings and provides error
feedback for system call failures, enhancing user experience. With a user-
friendly prompt (shell>), it incorporates a built-in mechanism for graceful
termination via the "exit" command. Additional features include handling a
maximum of 99 arguments, potential support for input/output redirection and
command piping, and a framework for implementing built-in commands. This
implementation serves as an educational tool, offering insights into process
management, inter-process communication, and the foundational elements of
shell functionality in Unix-like environments, making it a valuable resource
for students and developers interested in systems programming.
TABLE OF CONTENTS

Chapter No. Title Page No.


ABSTRACT v
LIST OF TABLES viii
LIST OF FIGURES ix
LIST OF ABBREVIATIONS x
INTRODUCTION 1
1 1.1 Overview 1
1.2 Problem Statement 1
1.3 Objective of the Project 2
1.4 Scope of the Project 2
SOFTWARE AND HARDWARE 10
SPECIFICATIONS
2 2.1 Hardware Requirements 10
2.2 Software Requirements 10
PROJECT DESCRIPTION 12
3.1 Introduction 12
3 3.2 Architecture Diagram 13
3.3 Algorithm Used 14
3.4 Advantages of Algorithm used 16
3.5 Explanation of the Project 39
3.6 Output Results 42
3.7 Conclusion 46
APPENDIX 49
Source Code 49
LIST OF TABLES

Table No Table Name Page No.


2.1 Comparison of various models on 9
different datasets
2.1 Input Parameters 18
2.2 Spooky Author verification dataset - 18
Train
2.3 Spooky Author verification dataset - 18
Test
LIST OF FIGURES

Fig No. Figure Name Page No.


4.1 Use of RNN in the speaker 15
verification system
4.2 Use of CNN in the speaker 16
verification system
4.3 Architecture Diagram 17
4.4 Dataframe information 18
4.5 Dataset Row Counts 21
4.6 Random Seed 21
4.7 Pre-Processing of Each Word 22
4.8 Pre-Processing Architecture of Text 22
Data
4.9 Tokenization of Sentence 23
4.10 Normalization of text data 24
4.11 TF-IDF Vectorizer 25
4.12 Random Forest Hyperparameters 26
4.13 Random Forest Precision 27
4.14 Visual Representation of Random 28
Forest Classifier
LIST OF ABBREVIATIONS

CNN Convolutional Neural Network


RNN Recurrent Neural Network
NN Neural Network
ASR Automated Speech Recognition
NLTK Natural Language Toolkit
LSTM Long Short-Term Memory
GRU Gated Recurrent Unit
SV Speaker Verification
CHAPTER 1

INTRODUCTION

1.1 Overview

This project presents a basic command-line shell implemented in C++,


designed to facilitate user interaction with the operating system through direct
command execution. It features an intuitive prompt for user input, which is
tokenized into individual arguments, accommodating a variety of command
structures and options. The shell distinguishes between foreground and
background processes based on the presence of an "&" character at the end of
commands, allowing users to run multiple commands simultaneously without
blocking further input, thus enhancing usability. Utilizing system calls like
fork() to create child processes and execvp() to execute commands, the
program efficiently manages process creation and execution. Comprehensive
error handling is integrated, providing informative feedback for failed
operations, which contributes to a more user-friendly experience. The shell
also supports a maximum of 99 arguments per command, ensuring flexibility
in command execution. Users can exit the shell gracefully by entering the
"exit" command. Moreover, the project establishes a foundation for potential
future enhancements, such as implementing input/output redirection,
command piping, and built-in shell commands. It also encourages exploration
of additional features like command history and user-defined aliases,
providing a richer shell environment

1.2 Problem Statement

The problem addressed by this project is the need for a basic yet
functional command-line shell that enables users to interact with the
operating system efficiently. Many existing shells can be complex and
overwhelming for beginners, lacking simplicity in execution and user
1
interaction. This project aims to create a straightforward shell that
supports essential features such as command execution, both in the
foreground and background, while providing a user-friendly interface. By
implementing fundamental process management through system calls like
`fork()` and `execvp()`, the shell allows users to execute commands
seamlessly, handle errors gracefully, and terminate sessions easily with
the "exit" command. This project ultimately seeks to bridge the gap for
users looking for an accessible entry point into command-line operations
and system programming, fostering a better understanding of the
underlying principles of Unix-like systems.

1.3 Aim of the Project

The aim of this project is to develop a basic command-line shell in


C++ that provides users with a simple and intuitive interface for executing
system commands while enhancing their understanding of process
management and system programming. The shell is designed to support
essential features such as foreground and background command execution,
dynamic argument handling, and robust error feedback, thereby improving
usability for both novice and experienced users.

1.4 Scope of the Project

The scope of the project includes implementing fundamental


functionalities like command tokenization, process forking, and execution
using system calls such as fork() and execvp(). It supports essential features,
including the ability to handle a maximum of 99 arguments per command,
process management, and graceful session termination. Additionally, the
project lays the groundwork for future enhancements, such as input/output
redirection, command piping, and built-in commands, which can further
enrich the user experience.

2
CHAPTER 2

SOFTWARE AND HARDWARE SPECIFICATIONS

2.1 Hardware Requirements

 Standard computer or laptop with sufficient processing power


 Minimum 1 GB of RAM to ensure smooth performance
 Modern processor capable of handling basic command execution
 Keyboard for efficient user input
 Monitor for displaying command output and user prompts
 Sufficient storage space for the operating system and project files

2.2 Software Requirements

The program prerequisites for this venture are as takes after:

• The primary software requirement for this project is a Unix-like operating


system, such as Linux or macOS, which provides the necessary environment
to utilize essential system calls like fork() and execvp(). These system calls
are critical for process management and command execution, enabling the
shell to create child processes and execute user commands efficiently. A
Unix-like environment also ensures compatibility with command-line utilities
and tools that enhance the development and testing experience

• In addition to the operating system, a C++ compiler is crucial for compiling


the source code of the shell application. Popular choices include GCC (GNU
Compiler Collection) and Clang, both of which offer comprehensive support
for C++ programming and adhere to modern language standards. The
compiler must be properly installed and configured to ensure that the shell
application compiles successfully without errors. This capability allows
developers to test and debug their code efficiently, ensuring the application
3
runs smoothly.
• A text editor or integrated development environment (IDE) is also essential
for code editing and development. Options range from lightweight editors like
Vim or Nano, which are ideal for quick edits, to more feature-rich IDEs such
as Visual Studio Code, Code::Blocks, or Eclipse. The chosen editor should
support C++ syntax highlighting, code completion, and debugging features to
enhance productivity and streamline the coding process. A user-friendly
interface can significantly improve the development experience, especially for
those who may be new to C++ programming.

• Furthermore, version control software, such as Git, is recommended to


manage code changes and collaborate effectively if the project involves
multiple developers. Using Git allows for tracking revisions, branching, and
merging code, making it easier to maintain the project's integrity over time.
Additionally, platforms like GitHub or GitLab can facilitate code sharing and
project management, enabling easier collaboration and contribution from
other developers.

• Finally, the development environment should support basic command-line


operations to facilitate testing and interaction with the shell. This includes the
ability to run commands directly within the terminal, providing a realistic
experience that mirrors user interaction with the final shell application.
Ensuring that the development setup is conducive to command-line operations
is essential for effectively testing the shell's functionalities and for providing a
seamless user experience during project development.

4
CHAPTER 3

PROJECT DESCRIPTION

3.1 Introduction

In the realm of computer science and software development,


understanding how operating systems interact with user commands is
fundamental. This project focuses on creating a basic command-line shell in
C++, providing a practical application that enables users to execute system
commands efficiently. A command-line shell serves as an intermediary
between the user and the operating system, interpreting user input and
executing the corresponding commands. By developing this shell, the project
aims to bridge the gap between theoretical knowledge and practical
application, offering a hands-on experience with fundamental concepts of
process management and command execution.

The shell is designed to be user-friendly while incorporating essential


features that enhance usability and functionality. Users can enter commands
in either the foreground or background, enabling multitasking capabilities that
are common in more advanced shell environments. The program utilizes
system calls like fork() to create child processes and execvp() to execute
commands, allowing for seamless command execution and efficient resource
management. This project not only reinforces core programming skills but
also provides insights into how shells operate, making it an invaluable
resource for students and developers interested in systems programming and
operating systems.

Furthermore, this project lays the groundwork for future enhancements


and features that can enrich the shell's capabilities. Potential improvements
include implementing input/output redirection, command piping, and support
for built-in commands, which would further replicate the functionality of
5
more sophisticated shells. By focusing on accessibility and simplicity, this
project serves as an educational tool for learners seeking to grasp the
underlying principles of Unix-like systems and shell operations. Ultimately,
this project exemplifies the intersection of theory and practice, equipping
users with the knowledge and experience needed to navigate and manipulate
command-line environments effectively.

In addition to its core functionalities, this project emphasizes robust


error handling and user feedback, crucial elements in creating a reliable
command-line interface. Users often encounter various issues when executing
commands, such as incorrect syntax or command not found errors. By
incorporating informative error messages, the shell helps users troubleshoot
problems effectively, enhancing their overall experience and understanding of
command-line interactions. This aspect of the project not only fosters a user-
friendly environment but also encourages users to learn from their mistakes,
reinforcing their command-line skills.

Moreover, the educational aspect of this project extends beyond just


building a shell; it serves as a foundation for exploring more advanced topics
in system programming and operating systems. As users become comfortable
with the basic functionalities of the shell, they can experiment with adding
new features or modifying existing ones, thus deepening their understanding
of process management, memory allocation, and system calls. This iterative
learning process promotes a hands-on approach to problem-solving and
software development, empowering users to innovate and create more
sophisticated tools in the future.

3.2 Algorithm Used

6
The algorithm for the command-line shell project begins by initializing
the shell environment and displaying the prompt for user input, inviting users
to enter commands. It reads an entire line of input, tokenizes it into individual
arguments using space as a delimiter, and checks if the user has entered the
"exit" command to gracefully terminate the shell. The algorithm then
determines if the command should run in the background by checking for an
"&" at the end of the input, setting a flag accordingly. Following this, it forks
a new process using the `fork()` system call; if the fork is successful, the child
process attempts to execute the command using `execvp()`, replacing its
memory space with the new command. If execution fails, the child process
outputs an error message and exits. Meanwhile, in the parent process, if the
command runs in the foreground, it waits for the child process to complete
using `waitpid()`, allowing for proper synchronization. After the command
execution, the shell loops back to display the prompt again for new user input,
continuing this cycle until the user chooses to exit. Additionally, the
algorithm includes robust error handling to provide informative feedback for
any failures encountered during the forking or execution processes, thereby
enhancing the overall user experience and promoting learning through
interaction. This structured approach not only facilitates efficient command
handling but also prepares the foundation for potential future enhancements,
such as adding input/output redirection and support for more complex
command structures.

The design also considers potential edge cases, such as handling


empty input or incorrect command syntax, to ensure resilience against user
errors. Furthermore, it lays the groundwork for future enhancements, such as
implementing input/output redirection and command piping, which would
allow for more complex command chains and interactions, making the shell
more versatile and powerful. Overall, this structured approach not only

7
facilitates efficient command handling but also encourages exploration and
experimentation with advanced shell functionalities, providing a
comprehensive educational tool for understanding operating systems and
command-line interfaces.

Advantages of Algorithm used:

 Simplicity: The straightforward design makes it easy to understand and


modify, providing an accessible entry point for learners.
 Efficiency: Utilizes system calls like `fork()` and `execvp()`, allowing
for effective process management and quick command execution.
 Error Handling: Incorporates robust error management to inform
users of issues, enhancing usability and learning.
 Foreground and Background Execution: Supports both execution
modes, enabling multitasking and improved user experience.
 Dynamic Input Handling: Capable of processing variable numbers of
arguments, accommodating a wide range of command structures.
 Looping Mechanism: Continuously prompts for input until exit is
requested, allowing for a seamless user experience.
 Foundation for Enhancements: Establishes a base that can be
expanded with additional features like input/output redirection and
command piping.
 Real-World Application: Mimics the functionality of real command-
line shells, providing practical experience with operating system
interactions.

8
 Educational Value: Promotes understanding of operating system
concepts, process management, and command-line operations through
hands-on experience.

Architecture Diagram

Figure 3.3: Architecture Diagram

We combine convolutional neural systems and repetitive neural


systems in our demonstrate and Comparing with Machine Learning Models
Which Include Random Forest Classifier and Adaboost Classifier as shown in
Figure 4.3. The Neural Network Model includes various Layers like
embedding, pooling, dense, transformer. The dataset is taken as input and
then the pre-processing is done. After pre-processing, the dataset is further
filtered by normalization and the dataset is operationalized using tokenization.
We will use TfidfVectorizer which is a popular feature extraction method
used in natural language processing (NLP) to transform text data into
numerical vectors.

The TfidfVectorizer is used to convert the pre-processed text into a


matrix of TF-IDF features. The dataset is partitioned into two subsets - one
for preparing and the other for testing purposes and then passed to Various
ML models and Various Neural network layers.

9
APPENDIX

10
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') {

11
cmd++;
}
}
*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);
}

12
}

int main() {
char cmd[MAX_LINE];
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];

13
if (getcwd(cwd, sizeof(cwd)) != NULL) {
printf("%s\n", cwd);
} else {
perror("getcwd() error");
}
} 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];

14
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);
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++;

15
}

if (is_redirect) {
if (fork() == 0) {
dup2(fd, 1);
close(fd);
execvp(cmd1[0], cmd1);
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");

16
}

if (fork() == 0) {
dup2(pipefd[0], 0);
close(pipefd[0]);
close(pipefd[1]);
execvp(cmd2[0], cmd2);
perror("Exec failed");
}

close(pipefd[0]);
close(pipefd[1]);
wait(NULL);
wait(NULL);
} else {
execute_command(argv);
}
}
}
return 0;
}

4.2 Compilation

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,
17
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

RESULTS

The proposed system uses a combination of the neural networks,


particularly CNN and RNN. Then we use the multi-layer model of the neural
networks on the Spooky Author Verification Dataset. The layers used in this

18
multi-layer model are: Multi Head Self Attention, Transformer Block, Token,
and And Position Embedding. For a predetermined number of epochs we
trained the model. allowing the model to gradually learn and improve its
accuracy and minimizing its loss. By taking these predictions into the account
our model achieves highest accuracy averaging at 96.4%. In order to improve
representational capacities while managing network dimensionality and
utilizing less computing and training resources, a unique technique to speaker
verification has been put forth. The dconv model offers a cost-effective
solution and has the capability to extract high-resolution features during the
training process.

Output

The confusion matrix is a table that compares the estimated and actual
values with test data to show how well the classification model is
performing.It can be used to assess the system's performance in terms of
correctly identifying speakers and excluding impostors in the context of
speaker verification.

A confusion matrix for speaker verification can be created as follows:

● True Positive (TP): the quantity of instances where the system


successfully recognises a real speaker.

● False Positive (FP): how frequently a fake speaker is mistakenly

19
identified as a real one by the system.

● True Negative (TN): the quantity of instances where the system rejects
the imposter

● False Negative (FN): how many times a genuine speaker is mistakenly


rejected as a fake by the system.

Conclusion

In the research, we develop a Neural Network model that is


computationally cheap and can be trained to extract high-resolution
features. On the Spooky Author dataset, many iterations of the NN model
were assessed and contrasted with ensemble techniques like Random
Forest Classifier and AdaBoost Classifier. The system improves the
spectral representation of utterances by focusing on individual frequency
bins. The results of our experiments show a notable improvement in the
functionality of different NN models.Th e Neural Network Model which is
the best-performing model with the highest accuracy, averaging at 96 %.
Instead of dropping unreliable data, we incorporate the predicted posterior
probability target distribution to avoid fitting into incorrect samples. We
created the input characteristics for the model and trained it on our dataset
using hyper parameters.

20

You might also like