Using fork(), pipe(), execlp() and dup() (see man 2 dup), write a C program executing the command ps -j in a parent process, displaying the result in a child process.
You are using the pipe itself, 100%. The only difference is what file descriptors the pipe is sitting at.
Not all the dups are necessary, the parent can just read directly from the reading end of the pipe. But the child process, /bin/ps, doesn't know or care that you have a pipe open -- it writes to standard output, no ifs, ands, or buts. The only way to tell it to write to your pipe, is to make it's standard output the pipe.
I would check out the freopen function. I think you can place it just before your exec() call and the new process would inherit the open file descriptors ( someone correct me if I'm wrong ).
NAME
fopen, fdopen, freopen - stream open functions
SYNOPSIS
#include <stdio.h>
FILE *fopen(const char *path, const char *mode);
FILE *fdopen(int fildes, const char *mode);
FILE *freopen(const char *path, const char *mode, FILE *stream);
DESCRIPTION
...
The freopen function opens the file whose name is the string pointed to by path and
associates the stream pointed to by stream with it. The original stream (if it
exists) is closed. The mode argument is used just as in the fopen function. The
primary use of the freopen function is to change the file associated with a stan-
dard text stream (stderr, stdin, or stdout).
Standard input, standard output, and standard error are always sitting at the same file descriptors... stdin is file #0, stdout is file #1, and stderr is file #2. To make them point anywhere else, you duplicate another file descriptor overtop of them; this will force that file descriptor to point somewhere else. That's what the dup2 calls are for.
That's what the dup2 calls are doing already. The stdio method could work, but it's best not to use stdio functions with file descriptors -- stdio has it's own buffers, etc. that can do strange things when forking.