rendered paste body#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
if (pipe(fd)==-1) {
printf(" pipe failed \n" );
}
childpid = fork();
if (childpid==0) { /* ls is the child */
if (dup2(fd[1] , 1) == -1) {
perror("Failed to redirect stdout of ls");
}
else {
if (execl("/bin/cat", "test.txt", NULL) == -1) {
perror("catting test failed");
}
}
return 1;
}
if (dup2(fd[0], 0) == -1) /* word count is the parent */
perror("Failed to redirect stdin of sort");
else {
if (execl("/bin/sort", NULL) == -1) {
perror("could not sort anything");
}
}
return 1;
}
//test.txt is this
sortthis.txt
//sortthis.txt
5
3
1
4
2