Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

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

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students also viewed these Databases questions

Question

How to solve maths problems with examples

Answered: 1 week ago

Question

3. Are our bosses always right? If not, what should we do?

Answered: 1 week ago