d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Homework Reguarding Pipes In C Program > Descrip Inside
Add Reply New Topic New Poll
Member
Posts: 13,893
Joined: Oct 21 2007
Gold: 1,244.00
Apr 15 2013 08:28pm
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]);

}




}
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Apr 17 2013 01:28pm
what does not work about it? have you tried to compile with -Wall and -g and open it up in gdb?

how is your program behaving differently than what it is supposed to be.

i hate posts like these where people go "hey heres my code idk why its not working fix it"
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll