Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help would be grreatly appreciated. Write a C program for Linux called pipes.c that does the following: In the main() function, it creates a pipe

Help would be grreatly appreciated.

image text in transcribed

Write 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 "ps -aux" command. Child 2 redirects its input from stdin to the read end of the pipe, then it executes the "sort -r -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 Child2 first, followed by Child 1. The parent program does the same thing as a shell that runs the command "ps-aux | sort -r-n -k 5". You must use the fork(), pipe(), dup2(), close(), execlp() functions (or other exec() variation)

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

Guide To Client Server Databases

Authors: Joe Salemi

2nd Edition

1562763105, 978-1562763107

More Books

Students also viewed these Databases questions