I am having some difficulties in the following thing:
I am trying to send a pipe to a child node within a function, and then have the child writing into it.
The following code parts will explain it better:
int p[2];
int i;
pipe(p);
close(p[1]);
if(fork1() == 0){
close(p[0]);
runcmd(parsecmd(buf),p);
}
wait(0);
}
while(read(p[0],&i,sizeof(int)) != 0){
printf(1," id: %d\n",i );}
and runcmd will have the following code:
...
void runcmd(struct cmd *cmd,int pp[]){
int j = getpid();
write(pp[1],&j,sizeof(int));
close(pp[1]);
...
sadly the expected result should be - the parent will print the id (getpid is a function that returns the current running process id ), but it doesn't, it prints nothing when evokes. what did I do wrong?