Question
In this assignment you will write your own shell. This will be quite a simple shell and will not have most of the features of
In this assignment you will write your own shell. This will be quite a simple shell and will not have most of the features of existing shells. The aim of the exercise is to gain some insight into the operation of a shell and how processes are combined in the shell. The mysh.h file contains the declarations of the data structures that are produced by the command parser. The parser.c and mysh.h files are taken from a working solution, so there should be no need to modify them.
Input to mysh is processed one line at a time. There will be one command on each line and commands cannot span several lines. Shell files can have comments, they start with the # character and go to the end of the line. Your program should read comments, but doesnt to do anything with them. This is handled in the command parser. In general, an input line will look like the following: command
In the case of a command the first string is the name of the program to execute and the remaining strings are the arguments to the command. This will all be packaged into an argv array when the program is executed. The end of a command is indicated by an end of line, or one of |, . Examples of commands are: program program output program arg1 arg2 arg3 prog1 arg1 | prog2 arg1 arg2 | prog3 >output The data structure constructed by the parser consists of a linked list with one entry for each command in the pipeline. This entry has any file redirections along with a pointer to another list with one entry for each argument. This data structure is dynamically allocated as the command line is parsed. Pipeline Execution In general, there will be several processes that are connected by pipes. The first process may have a redirected input file and the last process may have a redirected output file. The execution module needs to create these processes and the pipes that connect them. If there is more than one process in a pipeline, there must be a pipe connecting them. The execution module will need to fork a child process for each command in the pipeline. The child process will construct the argv array for the process, create a pipe if required, and do redirection if required. One of the exec functions that does a PATH search should then be used to start the program. This can be done in a loop. This part of the program waits for the last process in the pipeline to terminate and then returns. The shell command can be handled as a special case before the loop used to create the pipeline. Note, this part of the program is responsible for freeing the command line data structure that was allocated in the command line parser.
exec.c The exec function that executes a command pipeline. #includeStep 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