#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main(void) {
pid_t childpid;
int fd[2]; //file descriptor1
int fd2[2];//file descriptor2
//pipe them both
if (pipe(fd)==-1 || pipe(fd2) == -1) {
printf(" i blame capitalism \n" );
}
//connects both ends of pipes via dupe
if (dup2(fd[0], fd2[1]) == -1 ) {
printf(" failed at connecting\n");
}
childpid = fork();
/* Hi is the child */
if (childpid==0) {
if (dup2(fd[1] , 1) == -1) {
perror("Failed to redirect stdout of ls");
}
else {
printf("HI\n");//Send HI to fd[1].
}
return 1;
}
/* word count is the parent */
if (dup2(fd2[0], 0) == -1) //Get output from fd2[0]
perror("Failed to redirect stdin of sort");
else {
execl("/usr/bin/wc", "-cl", NULL);//exec should read fd2[0]'s output
perror("could not call anything");
}
return 1;
}