#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h> int main()
{
int fds[];
pid_t pid; pipe( fds );
pid = fork();
if( pid == (pid_t) )
{
close( fds[] );
dup2(fds[], STDIN_FILENO );
execlp( "sort", "sort", );
}
else
{
FILE *stream;
close(fds[]);
stream = fdopen( fds[], "w" );
fprintf( stream, "This is a test.\n" );
fprintf( stream, "Hello, world.\n" );
fprintf( stream, "My dog has fleas.\n" );
fprintf( stream, "My dream will come true.\n");
fflush( stream );
close( fds[] );
waitpid( pid, NULL, );
}
}
05-04 05:04