Question: 2 Pipeline command Complete the main function in pipes.c to implement the following pipeline command: ls / dev | xargs | cut - d -

2 Pipeline command
Complete the main function in pipes.c to implement the following pipeline command:
ls /dev | xargs | cut -d-f-
where -d is followed by a white space within single-quotes and and are positive integers
specified as command line arguments of your program.
Lets understand what the pipeline command does. It consists of three external commands, which can
take zero or more arguments, chained together to form a single instruction. The 3 stages of the pipeline
are as follows:
1. The first stage, ls /dev, outputs the list of files in /dev into a pipe.
2. The second stage, xargs, takes the output of stage 1 on its standard input, delimits it by
blanks, and sends the output into the second pipe.
3. The third stage, cut -d-f-, takes the output of stage 2 as its input and prints
the selected fields (in the range a to b) on the standard output delimited by a whitespace. Note
that the pair of quotes after -d are not needed when passing arguments through execl.
Below are sample outputs from running the program on Github Codespaces. Note that the output may
vary on your local machine. The length of each output, however, should be the same as the below
examples.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!