assignment5
assignment5
PRESENTATION BY
GROUP MEMBERS
1. Vishal Chakradhari Yennam
2. Soham Rajesh Pitale
3. Shreyash Ashok Vekhande
4. Ayyan Safi Bardi
2
CONTENTS
o Basic Structure of a Shell
o Basic example in C
o Input Parsing: Reads the command input from the user and parses it into executable commands
and arguments.Additional Features for EnhancemenSummary.
o Loop: A shell typically runs in a loop, reading commands, executing them, and returning to the
prompt until an exit command is given.
STEPS TO IMPLEMENT A BASIC SHELL
o Tokenize the string (using strtok in C, or split() in Python) to separate each word based on spaces.
4. Execute Commands
o Use system calls to run the parsed commands.
o Handle built-in commands like cd, exit, or any shell-specific commands manually in the shell code.
o Allow the user to exit the shell by typing commands like exit or quit .
BASIC EXAMPLE IN C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#define MAX_ARGS 64
void shell_loop() {
char input[MAX_INPUT];
char *args[MAX_ARGS];
BASIC EXAMPLE IN C
int should_run = 1;
while (should_run) {
printf("$ ");
// Parse input
int arg_count = 0;
arg_count++;
BASIC EXAMPLE IN C
args[arg_count] = strtok(NULL, " ");
if (strcmp(args[0], "exit") == 0) {
should_run = 0;
continue;
if (pid < 0) {
perror("Fork failed");
BASIC EXAMPLE IN C
} else if (pid == 0) {
execvp(args[0], args);
perror("Execution failed");
exit(1);
} else {
}}}
int main() {
shell_loop();
return 0;
}
C O M P I L I N G A N D RU N N I N G
gcc -o simple_shell simple_shell.c
./simple_shell
CONCLUSION
In summary, implementing a simple shell offers hands-on experience with key operating system
concepts like process management, command parsing, and system calls. This project strengthens your
understanding of how commands interact with the system and builds a foundation for more
advanced OS features, making it an excellent step toward mastering systems programming.
REFERENCES
https://chat.open.ai/
https://geeksforgeeks.com/
https://www.inuxfromscratchguide.com/
T H A N K YO U