tags:

views:

70

answers:

1

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:

  1. Fork my process
  2. create pipe
  3. dup2(pipe[0],STDOUT_FILENO) my child's stdout
  4. poll the file descriptor of the pipe(I do this until I reach EOF)
  5. 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??

+1  A: 
(poll_fds[idx].revents & ~POLLIN)

What the heck? That returns true if any non-POLLIN bits are set. Probably you want one of

!(poll_fds[idx].revents & POLLIN)
(~poll_fds[idx].revents & POLLIN)
ephemient
true, it returns false if POLLIN is set.... meaning that Im not finished. my_pipe->in_EOF = (poll_fds[idx].revents
marco
But it returns true if `revents = (any other flag) | POLLIN`.
ephemient
absolutely true thanks ;)
marco