Hello,
I am creating a child-parent fork()
to be able to communicate with a shell(/bin/sh
) from the parent through a pipe.
The problem is:
In a parent I set a select()
on a child output, but it unblocks only when the process is finished! So when I run say ps
it's okay. but when I run /bin/sh
it does not output until shell exits. But I want to read it's output!
for(;;) {
select(PARENT_READ+1,&sh,NULL,NULL,NULL); // This unblocks only when shell exits!
if (FD_ISSET(PARENT_READ,&sh)) {
while (n = read (PARENT_READ, &buf,30)) {
buf[30]='\0';
printf("C: %s\n",buf);
};
};
}
The answer is somewhere in the field of disabling buffering of pipes?