I’m a noob to linux programming, so please bear with me. In my application, I fork(), then execl() another binary after having setup a single pipe for reading in. After the fork and exec are OK, i do a dup2() for reading in from the stdout of the executed binary. I need my parent application to wait for output from the process it has created and once there is output, read it. I figured I will use select(), and wait for a few milliseconds before trying to see if there is data to be read and if there is, use read(). However my code does not work because select() takes as argument an fd_set, while my pipe is of int converted by pipe() and dup2(). What can I do to overcome this and is there another alternative? Note, I’m not blocking the parent process until the process ends, but want to read info while the child process runs.
Share
To use
select()you must create astruct fd_setand populate it using theFD_macros. In this way you will inform the function which descriptors you are interested in (note that it is common to be interested in several at once). For example:The first argument to select is to be the highest-numbered file descriptor you are interested in, plus one. That, along with example code, is explained here:
http://linux.die.net/man/3/fd_set