Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm 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 Date: Wed, 8 May 2002 11:42:54 -0400 (EDT) From: David E Euresti To: Subject: Socket Handles duplicated twice after fork Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Hello, I've been trying to get the developers attention to this problem but have failed at it. Perhaps the third time is the charm. Below we have some code that creates a socketpair and forks. Then each process tells you what the handle of the sockets are. The output looks something like this: Parent: Sockets are 0x10c 0x104 Child: Sockets are 0xc 0x10 Now if you run sysinternals's Process Explorer (www.sysinternals.com) and click on the parent process you'll see that sure enough the handles 0x10c and 0x104 are there and point to a /Device/Afd/Endpoint. Now if you go to the child process you'll see that 0xc and 0x10 are there and pointing to /Device/Afd/Endpoint. However you'll also notice that 0x10c and 0x104 are also there. This is were the error is. The bad part is that you don't have access to those handles to close them so they will always remain open even if you close 0xc and 0x10. This was all tested in Win2k. Let me know what you guys think. Is this an error in Cygwin, is it fixable, is this an error in my code? Thanks. #include #include #include #include int main() { int fds[2]; int pid; socketpair (AF_UNIX, SOCK_STREAM, 0, fds); pid = fork (); if (pid == 0) { printf("Child: Sockets are 0x%x 0x%x\n", get_osfhandle(fds[0]), get_osfhandle(fds[1])); sleep(300); } else { printf("Parent: Sockets are 0x%x 0x%x\n", get_osfhandle(fds[0]), get_osfhandle(fds[1])); sleep(300); } } -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/