| www.delorie.com/archives/browse.cgi | search |
| X-Recipient: | archive-cygwin AT delorie DOT com |
| DomainKey-Signature: | a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id |
| :list-unsubscribe:list-subscribe:list-archive:list-post | |
| :list-help:sender:date:from:to:subject:message-id:mime-version | |
| :content-type; q=dns; s=default; b=fOtw/T6hZB/2zpXJkWyJTdGLiQnzR | |
| rR5BT1uVvZZ3/FAKn2eRomYEgwqnKlFwpo+Y/99dlIO9GS9gET1qHud3LRUEIgR3 | |
| EitGeohSm+0bxqsR4Q71xC7lxRHEk5I94KOpVkis9s9i/w7BsjUqvOdpcM1hZtgl | |
| L5UFSBRQWJ1F10= | |
| DKIM-Signature: | v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id |
| :list-unsubscribe:list-subscribe:list-archive:list-post | |
| :list-help:sender:date:from:to:subject:message-id:mime-version | |
| :content-type; s=default; bh=Oz0J/zD9iJRYY8x7IoafAkqm0/s=; b=XaT | |
| ASjI3udYIbxHNFUsC+pUh2y7rwqh6LdpXpMs0puc0oqrCj2ehOXqe6DPMJkphomn | |
| jmdodVWk5UhaCU5rxWPFoG4CP7XYcHOgZDIr3fe8zkw/hK3a7wspo2yva+Zekwty | |
| jVvbKuAgLj31Dh5wsJkPNI0E/PUTHdtnWVyT9aD4= | |
| Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
| List-Id: | <cygwin.cygwin.com> |
| List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
| List-Archive: | <http://sourceware.org/ml/cygwin/> |
| List-Post: | <mailto:cygwin AT cygwin DOT com> |
| List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
| Sender: | cygwin-owner AT cygwin DOT com |
| Mail-Followup-To: | cygwin AT cygwin DOT com |
| Delivered-To: | mailing list cygwin AT cygwin DOT com |
| 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 |
| DKIM-Filter: | OpenDKIM Filter v2.10.3 conssluserg-03.nifty.com v29BdwqT011417 |
| X-Nifty-SrcIP: | [175.179.23.201] |
| Date: | Thu, 9 Mar 2017 20:39:59 +0900 |
| From: | Takashi Yano <takashi DOT yano AT nifty DOT ne DOT jp> |
| To: | cygwin AT cygwin DOT com |
| Subject: | fork() fails if it is called recursively from a child thread. |
| Message-Id: | <20170309203959.1e7e32d20bf7ec06c705d3ba@nifty.ne.jp> |
| Mime-Version: | 1.0 |
| X-IsSubscribed: | yes |
--Multipart=_Thu__9_Mar_2017_20_39_59_+0900_1.5CHGQL=VSqiEM9
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
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 <takashi DOT yano AT nifty DOT ne DOT jp>
--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
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <pthread.h>
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
--
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--
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |