Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in UNIX Design and implement a C/C++ program (a3part3.c) to implement a simple shell. Warning: you should not use any system call . Your program

in UNIX

Design and implement a C/C++ program (a3part3.c) to implement a simple shell.

Warning: you should not use any "system" call .

Your program will run in a loop: (1) get the input from the user, (2) parse it, (3) for each command in pipe, set it for pipe, set each file-redirection specified for the command, fork a process to run it (via exec), and (4) back to the loop for next command.

If the command is "exit", then the program terminates.

Task1. 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

ls /etc | grep "*.c" | sort > a3out.txt

ls | grep ".c" | sort | wc l > 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 "ls" 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.

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

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions

Question

Give examples of behavioral indications of fraud.

Answered: 1 week ago