In this program, need to implement functions by chaining the standard Unix utility programs. In particular, you are asked to produce a program that runs a sequence of commands. For example,
$ ./combo cmd1 cmd2 cmd3
Assuming cmd1, cmd2, and cmd3 are three separate programs, such as ls, cat, sort, and so on. The first program cmd1 reads from the standard input and produces the standard output, which is piped to the second program cmd2 as its standard input. The second program cmd2 reads from the standard input and writes to the standard output, which is piped to the next program, so on and so forth.
The above example runs the same as:
$ cmd1 | cmd2 | cmd3
The combo program must take at least one programs. Note that you're not asked to implement the individual programs, cmd1, cmd2, and cmd3 as in the above example. You are asked instead to fork processes and use exec (or its variants) to run the programs. You are also asked to use pipe and dup (or dup2) to facilitate communication between the processes (i.e., rewiring the standard input and output for the processes before you exec them).
Start by checking out the examples in the CProg/pipes directory
For the program, the logic is as follows:
Here's an example:
./combo ls sort
Makefile
combo
combo.c
combo.o
The program runs 'ls' to list the files in the current directory, which is then sorted. The result is printed to the standard output. Here's another example
./combo cat sort wc < Makefile
10 24 137
The first program is 'cat'. Rather than providing a filename as its argument, we redirect the text file 'Makefile' as its standard input. 'cat' lists the content of the file (given as stdin), which is then sorted, and then counted for lines, words, and characters.