X-Recipient: archive-cygwin AT delorie DOT com X-Spam-Check-By: sourceware.org Date: Sun, 11 Apr 2010 02:29:18 -0400 From: Christopher Faylor To: cygwin AT cygwin DOT com Subject: Re: Usage of _exit(0) closes fd's of parent process Message-ID: <20100411062918.GB7269@ednor.casa.cgf.cx> Reply-To: cygwin AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com References: <20100411054851 DOT GA25578 AT roll> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20100411054851.GA25578@roll> User-Agent: Mutt/1.5.20 (2009-06-14) Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com On Sun, Apr 11, 2010 at 01:48:51AM -0400, tmhikaru AT gmail DOT com wrote: >Hi. I'm having an unusual problem in a program I'm trying to get >working in cygwin. My program fork()'s a child process to do a >hostname lookup, establishes a tcp connection in the parent, then has >the child _exit(0) itself. For some reason I don't understand, _exit >is not just closing the fd's of the child, but of the parent as well. >From my understanding, _exit is supposed to close the fd's of the >process it is run from only. > >The program works correctly (That is to say, stays connected) if I >comment out the _exit and instead have it while (1) { sleep (10000); }. >Obviously I would like to be able to kill off the child at some point, >but for testing this proved to me that either my expectation of how >_exit is supposed to work in cygwin is flawed, or _exit is. > >Please let me know if I'm using this function call incorrectly, and >what behavior I should be expecting. If my expectation of how _exit is >supposed to act is correct, let me know and I'll file a bug report. While it is theoretically possible to close handles in the parent process it would be very unsual for Cygwin, or any program, to do something like that. And, in fact, Cygwin doesn't try to close handles in the parent when it exits. You need to go back and read http://cygwin.com/problems.html and then, take a step back, and report the problem that you're seeing rather than your conclusions about the problem. For instance, what does "stays connected" mean? Are you using sockets, pipes, a file, shared memory, etc.? cgf -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple