#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <fcntl.h>
int main (int argc,char *argv[])
{
int fd[2];
if(pipe(fd) == -1)
{
perror("pipe fail");
exit(1);
}
pid_t a =fork();
if(a>0) //parents
{
close(fd[0]);
dup2(fd[1],1);
//close(fd[1]);
execlp("ls","ls",NULL);
}
if(a==0) //children
{
close(fd[1]);
dup2(fd[0],0);
//close(fd[0]);
execlp("wc","wc","-w",NULL);
}
close(fd[0]);
close(fd[1]);
return 0;
}