From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 67317 invoked by alias); 9 Mar 2017 11:40:06 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 67287 invoked by uid 89); 9 Mar 2017 11:40:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.2 spammy=speaking, H*c:HHHH, died, H*F:D*ne.jp X-HELO: conssluserg-03.nifty.com Received: from conssluserg-03.nifty.com (HELO conssluserg-03.nifty.com) (210.131.2.82) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 09 Mar 2017 11:40:02 +0000 Received: from Express5800-S70 (ntsitm157201.sitm.nt.ngn.ppp.infoweb.ne.jp [175.179.23.201]) (authenticated) by conssluserg-03.nifty.com with ESMTP id v29BdwqT011417 for ; Thu, 9 Mar 2017 20:39:59 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-03.nifty.com v29BdwqT011417 X-Nifty-SrcIP: [175.179.23.201] Date: Thu, 09 Mar 2017 11:40:00 -0000 From: Takashi Yano To: cygwin@cygwin.com Subject: fork() fails if it is called recursively from a child thread. Message-Id: <20170309203959.1e7e32d20bf7ec06c705d3ba@nifty.ne.jp> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Multipart=_Thu__9_Mar_2017_20_39_59_+0900_1.5CHGQL=VSqiEM9" X-IsSubscribed: yes X-SW-Source: 2017-03/txt/msg00113.txt.bz2 --Multipart=_Thu__9_Mar_2017_20_39_59_+0900_1.5CHGQL=VSqiEM9 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-length: 1017 Hello, I found fork() fails if it is called recursively from a child thread. Simple test case, attached (fk.c), reproduces this problem. Expected result: Parent 0 [22034] exit. Child 0 [22036] works. Parent 1 [22036] exit. Child 1 [22038] works. Parent 2 [22038] exit. Child 2 [22039] works. Parent 3 [22039] exit. Child 3 [22040] works. Parent 4 [22040] exit. Child 4 [22041] works. Result in cygwin 2.7.0: Child 0 [4668] works. Parent 0 [7188] exit. 0 [main] a 4668 fork: child -1 - forked process 8456 died unexpectedly, retry 0, exit code 0xC0000142, errno 11 fork(): Resource temporarily unavailable Strictly speaking, the test case is not safe because it calls functions which are not async-signal-safe from forked child process, i.e. printf() and perror(), in spite of multi-thread. However the same happens even without printf() and perror(). This is the cause of which iperf 2.0.5 with option -s -D fails to start as daemon. Is this the known issue? -- Takashi Yano --Multipart=_Thu__9_Mar_2017_20_39_59_+0900_1.5CHGQL=VSqiEM9 Content-Type: text/x-csrc; name="fk.c" Content-Disposition: attachment; filename="fk.c" Content-Transfer-Encoding: 7bit Content-length: 550 #include #include #include #include #include void MoveToChild(int n) { pid_t pid; if ( (pid = fork()) == -1 ) { perror("fork()"); _exit(1); } else if ( pid != 0 ) { printf("Parent %d [%d] exit.\n", n, getpid()); _exit(0); } printf("Child %d [%d] works.\n", n, getpid()); } void *thread_main(void *args) { int i; for (i=0; i<5; i++) MoveToChild(i); return NULL; } int main() { pthread_t t; pthread_create(&t, NULL, thread_main, NULL); pthread_join(t, NULL); return 0; } --Multipart=_Thu__9_Mar_2017_20_39_59_+0900_1.5CHGQL=VSqiEM9 Content-Type: text/plain; charset=us-ascii Content-length: 219 -- 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 --Multipart=_Thu__9_Mar_2017_20_39_59_+0900_1.5CHGQL=VSqiEM9--