I want to read the output of my child's proccess, but for some reason it stops setting the POLLIN in revents when there is still output to be read.
Here is what I do:
- Fork my process
- create pipe
- dup2(pipe[0],STDOUT_FILENO) my child's stdout
- poll the file descriptor of the pipe(I do this until I reach EOF)
- read output if POLLIN is set
the way that I see if I have reached an EOF is by setting a flag in a struct if after poll there was no POLLIN set in revents.
(poll_fds[idx].revents & ~POLLIN)
Now this always evaluates to true even if POLLIN is set, I guess its beacuse some error flag is set on the bitmask, right??
the way i test my program is ./my_program /bin/ls
now this should print the output of ls on my console but it only prints the first 16 bytes (I read() exactly 16 bytes).
I dont know why the error flag is being set any ideas??
EDIT: I just saw that the flag that is being set is POLLHUP... but I dont understand why its being set if I sill have not read all the pipe??