Results 1 to 3 of 3
Hi everyone.. I have a question in the select call.
I have a process that forks, where the childs puts some data of random size and exits while the parent ...
- 12-08-2010 #1Just Joined!
- Join Date
- Oct 2009
- Posts
- 85
clarification in the select system call
Hi everyone.. I have a question in the select call.
I have a process that forks, where the childs puts some data of random size and exits while the parent should get the data and does some manipulation.. here I have used a pipe for child to write the data and parent to read the data..
Child simply dumps the data, and the data is of any size even child and parent doesnt know.
I have used select in the parent to see whether there is any data coming on the reading end of the pipe.. if there is a data.. I copy into a buffer.. Im reading the data continusly when the child exits after closing the writing end of pipe. Parent gets blocked on the read part
But my question is how parent know the other of pipe is closed when using the select call.
In otherwords.. while using select in readfds, how would i know the other end has closed the pipe..
- 12-08-2010 #2Just Joined!
- Join Date
- Nov 2006
- Location
- Harrisburg, PA, USA
- Posts
- 56
Parent should receive SIGPIPE signal indicating other end of pipe has closed. Your program should have signal handler to handle this signal and appropriately delete that file descriptor from select read fds.
I am not sure about what will happen on select(). But my guess is select() would return an error EBADF (Bad File Descriptor) whenever you try to read data out of invalid file descriptor which is the read end of pipe.
- 12-10-2010 #3Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
There are three sets of file descriptors (fd_set) used by select(): readfds, writefds, and execptfds. This last one is for exceptions/signals etc. This is where you should find out that the pipe/fd has been closed by the other end. Of course it only indicates that something has happened to the fd. You still need to determine what that is.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote