Simple shell os
Simple shell os
A MINI-PROJECT REPORT
Submitted By
DARUN M [RA2311030020004]
DEEPAK R [RA2311030020005]
SYED ABDUL WAHAB [RA2311030020013]
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,
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
INTRODUCTION
1.1 Overview
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.
2
CHAPTER 2
4
CHAPTER 3
PROJECT DESCRIPTION
3.1 Introduction
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.
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.
8
Educational Value: Promotes understanding of operating system
concepts, process management, and command-line operations through
hands-on experience.
Architecture Diagram
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>
11
cmd++;
}
}
*argv = '\0';
}
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
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.
19
identified as a real one by the system.
● True Negative (TN): the quantity of instances where the system rejects
the imposter
Conclusion
20