title: Unix - Pipe, forks, execlp, dup2, c program
body: <p>This is for an assignment. I am new to programming in unix and could use some help. I need to create a C program that does the following:</p>
  
  <p><strong><em>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 Child 2 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).</em></strong></p>
  
  <p>I am a senior year CS student and pretty savvy with windows programming, so I'm not asking for a solution, just a translation as to what exactly needs to be done and what the various commands all mean.</p>
  
  <p>Thanks</p>