Use pipes to pipe "who" unix command output to "sort" unix command and then into "more" unix command
my code compiles but definitely does not work. any help would be appreciated.
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
int main(){
int fd[2];
pipe(fd);
pid_t childId = fork();
if(childId > 0){
char readWho [256];
read(fd[0], readWho,256);
printf("/n, readWho);
}
else if(childId == 0){
dup2(fd[1],1);
execl("/bin", "who", NULL);
}else{
printf("error forking \n");
}
close (fd[1]);
childId = fork();
if(childId == 0){
dup2(fd[0],0);
execl("/bin", "sort",NULL);
}
childId = fork();
if(childId == 0){
dup2(fd[0],0);
execl("/bin", "more", NULL);
}
close(fd[0]);
}
}