Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Design and implement a C/C++program (a3part3.c [or a3part3.cpp]) to implement a simple shell. Warning: you should not use any system call throughout this assignment (and
Design and implement a C/C++program (a3part3.c [or a3part3.cpp]) to implement a simple shell. Warning: you should not use any "system" call throughout this assignment (and thereafter) Taski. Three or More Commands in Pipe You may use the sample code provided to handle two commands in pipe, to make a shell. Your shell handles one command, or two or three commands in pipe, for example, ls /etc | grep "passwd" sort Is /etc | grep ".c" sort> a3out.txt Is |grep ".c" sort | wc -1> a3out.txt or more commands in pipe For example, if there are three commands in pipe, the parent gets the command (for example, "ls /etc | grep passwd | sort") to recognize that there are three commands piped together. Thus the parent forks a child (to do sort - the last command). The child will create a pipe to be shared, and then fork a child process (to do grep-the command in the middle of the command-pipe) which will fork its child process (to do ls - the first command) with the pipe shared (so that the output of one process doing "Is" will be the input to the process doing grep command). Meanwhile the parent waits for the child processes (doing the last command in the pipe sequence) to be terminated, and then back to the loop for the next command from the user Note. You should review APUE09 Section 9 for the detail, the example, the diagram and the discussion. Note. You will have a main and a function named runNcommands to receive the input string (for example, " Is /etc | grep passwd | sort ". The function will parse the commands to be run in pipe Note. Do not enumerate a code segment for each case (case-by-case, that is, to write a code segment for 2 commands, a code segment for 3 commands, and for 4 commands, to handle max 4 commands) but to make your code generalized to handle any number of commands in pipe. You should have a for-loop to loop n times for n-commands in pipe to generate (fork) n-processes where each process creates a pipe to be shared with its child process. Task2. Provide a Makefile file to compile your program Task3. Program run and output with 3 test cases. Design and implement a C/C++program (a3part3.c [or a3part3.cpp]) to implement a simple shell. Warning: you should not use any "system" call throughout this assignment (and thereafter) Taski. Three or More Commands in Pipe You may use the sample code provided to handle two commands in pipe, to make a shell. Your shell handles one command, or two or three commands in pipe, for example, ls /etc | grep "passwd" sort Is /etc | grep ".c" sort> a3out.txt Is |grep ".c" sort | wc -1> a3out.txt or more commands in pipe For example, if there are three commands in pipe, the parent gets the command (for example, "ls /etc | grep passwd | sort") to recognize that there are three commands piped together. Thus the parent forks a child (to do sort - the last command). The child will create a pipe to be shared, and then fork a child process (to do grep-the command in the middle of the command-pipe) which will fork its child process (to do ls - the first command) with the pipe shared (so that the output of one process doing "Is" will be the input to the process doing grep command). Meanwhile the parent waits for the child processes (doing the last command in the pipe sequence) to be terminated, and then back to the loop for the next command from the user Note. You should review APUE09 Section 9 for the detail, the example, the diagram and the discussion. Note. You will have a main and a function named runNcommands to receive the input string (for example, " Is /etc | grep passwd | sort ". The function will parse the commands to be run in pipe Note. Do not enumerate a code segment for each case (case-by-case, that is, to write a code segment for 2 commands, a code segment for 3 commands, and for 4 commands, to handle max 4 commands) but to make your code generalized to handle any number of commands in pipe. You should have a for-loop to loop n times for n-commands in pipe to generate (fork) n-processes where each process creates a pipe to be shared with its child process. Task2. Provide a Makefile file to compile your program Task3. Program run and output with 3 test cases
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