Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A simple Linux shell: Your shell should repeatedly display a prompt and allow a user to enter a command to run. Your shell is supposed

A simple Linux shell: Your shell should repeatedly display a prompt and allow a user to enter a command to run. Your shell is supposed to read the input from system standard input, parse the line with command and arguments, and execute. You must only use fork() and execv() system calls to support the shell command execution.
Your shell should find the internal commands first (described below). If not found, it should search the directories in the shell's pathname environment.
You are not allowed to use system(), as it invokes the system's /bin/sh shell. You cannot use execlp() or execvp(), because your shell has its own pathname variable.
By convention, the command arguments are separated by white spaces. Your shell does not need to handle special characters, such as <,>,|, &, and so on.
Internal Commands: Implement the following 3 internal commands (running in the main process rather than the child process).
cd: is a command, obviously, to change directories. You are required to use chdir() system call.
path: is not only a command to show the current pathname variable content (if no argument is provided), but also a utility to modify (either add or remove) the pathname variable content.
path +/abc/def should append the pathname "/abc/def" to the pathname variable, which is a string. E.g.,"/bin:/sbin:/abc/def"(where ':' is a delimiter).
path -/abc/def should remove the pathname "/abc/def" from the existing pathname variable.
quit: is a command to leave the shell.
Give the above path command, you are NOT ALLOWED to use following functions to access a file name or obtain the pathname information: access(), getenv(), setenv(), etc.
A string parser: A (string) parser is a function that breaks an input string into parts, such as commands and parameters, which can be managed by other programming components. In this project, you are highly suggested to implement a string parser. The functionality and the structure of your string parser should be organized in the following steps.
Keyboard input: you are required to use fgets(buf,256, stdin) library function to take the keyboard input, where buf is a char pointer (to be declared),256 is the command length limit, and stdin the system standard input.
Parsing: given a command string stored in buf, suppose the content can be represented as "cmd arg1 arg2 arg3...".
your parser first breaks the string into a string array, for example token[]. The size of token[] should always be the number of words plus one. For example, given a command with 3 argument, your token[] size should be 1+3+1=5, where token[4] stores NULL.
your parser then checks whether "cmd"(stored in token[0]) is an internal command (as described above). If it is, then you perform this internal command in the parent process.
If it is not an internal command, then you must use fork()/execv() pair to arrange "cmd" to be executed in a child process. If "cmd" cannot be found (e.g., due to a typo), you need to output corresponding error message to the screen.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 2 Lnai 9285

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Joao Gama ,Alipio Jorge ,Carlos Soares

1st Edition

3319235249, 978-3319235240

More Books

Students also viewed these Databases questions

Question

Differentiate the function. r(z) = 2-8 - 21/2 r'(z) =

Answered: 1 week ago