delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/10/15/10:34:31

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-3.5 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_PASS
X-Spam-Check-By: sourceware.org
Message-ID: <4AD732C7.4020301@cwilson.fastmail.fm>
Date: Thu, 15 Oct 2009 10:33:43 -0400
From: Charles Wilson <cygwin AT cwilson DOT fastmail DOT fm>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: fork failure?
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
Note-from-DJ: This may be spam

I'm trying to track down a rather weird problem. I don't have an STC
because none of my attepted STCs exhibit the problem.  Schematically, I
have:

=============================================
pid_t pid = fork();

if (pid < 0) {
  printf("fork failed\n");
  exit (1);
}

if (pid > 0) {
  /* parent */
  printf("parent: child pid=%d\n", pid);
  sleep(30);
  exit(0);
}

/* child */
printf("child lives!");
sleep(30);
exit(0);
=============================================

although the actual app is much more complicated, AND an STC based on
the above actually works as expected. But, in the actual app, what
happens is:

1) fork appears to succeed, because I see:
parent: child pid=xxx

2) but fork fails, because I never see:
child lives!
Worse, I never see the pid xxx show up in 'ps' output, even though I
have plenty of time (30 seconds) to spot it (and STCs based on the above
simplification do work as expected; I see 'child lives!' and the process
shows up in 'ps').

I even tried (in the actual app) other methods of indication than
printing to some FILE*, since maybe stdout got scrogged by fork, such as:
a) writing to an inherited fd other than 0,1,2
b) writing to a brand new fd or FILE* opened by the child
c) simply touching a "sentinel" file to change its atime
Nothing. For all I can tell, the fork() fails to *actually* produce a
child process -- even though the *parent* seems to think one has been
created, and has a pid for the so-called child. Which doesn't actually
exist.

Can anybody think of a reason that might cause this behavior? I'm using
stock cygwin-1.7.0-62...

--
Chuck

--
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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019