At 18:13 Uhr +0800 29.07.2006, TJay wrote:
I'm new to multiprocess programming, but I know that if I fork an X program, the X connections "get duplicated", so the forked process shares the same window/etc as its parent...
There are, on unix, two ways to dispose of file descriptors in children: a) call fcntl with the close-on-exec flag, b) close the file descriptors explicitly using close.
Obviously the former will only help you if you later call exec, not if you want to only fork and have the fd closed in the child.
I'm wondering if programs compiled with Gambit can be cleanly forked, with the child and parent being completely separate.
I remember that Gambit closes filehandles if you call open-process. But that does not only a fork, it also exec's. My question is, how did you want to fork your child in the first place?
If you're using the C interface, you could probably just as well call close on all fd's which are not of your interest. (A way to do that (which some unix programs employ) is to just call close on all numbers from 3 to 1023 or something like that, of course that's not safe if there are more files open.)
I think you could wrap the gambit open functions so that you record their fd (or the port) in a global data structure (a weak table in the case of a port), register a release function which removes the entry again (and a wrapper around close-port doing the same), and upon fork call close on all recorded open fd's.
Maybe you should describe what you want to do in more detail, I can't imagine why you want that functionality from the top of my head except that you might have run into problems with multiple threads continuing to run in the child or with non-written buffers being flushed twice.
Christian.