Answered step by step
Verified Expert Solution
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 binsh 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 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 abcdef should append the pathname abcdef to the pathname variable, which is a string. Egbin:sbin:abcdefwhere : is a delimiter
path abcdef should remove the pathname abcdef 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 fgetsbuf stdin library function to take the keyboard input, where buf is a char pointer to be declared 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 arg arg arg
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 argument, your token size should be where token stores NULL.
your parser then checks whether cmdstored in token 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 forkexecv pair to arrange cmd to be executed in a child process. If cmd cannot be found eg 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started