Develop a c program for linux callednbsppipescnbspthat does


develop a C program for Linux called pipes.c that does the following:

In the main() function, it creates a pipe using the pipe() function, then creates two child processes with fork(). Child 1 redirects stdout to the write end of the pipe and then executes with execlp() the "ls -al" command. Child 2 redirects its input from stdin to the read end of the pipe, then it executes the "sort -n -k 5" command.

After creating both children, the parent process waits for them to terminate before it can exit.

Note that you may have to create Child 2 first, followed by Child 1.

The parent program does the same thing as a shell that runs the command "ls -al | sort -r -n -k 5".

You must use the fork(), pipe(), dup2(), close(), execlp() functions (or other exec() variation). You can edit your program with the geditapplication, available from the command line. Or install emacs using command "sudo apt-get install emacs" and learn to use it. 

 

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: Develop a c program for linux callednbsppipescnbspthat does
Reference No:- TGS01549288

Now Priced at $30 (50% Discount)

Recommended (96%)

Rated (4.8/5)