www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/11/03/05:59:05

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=BAYES_00
X-Spam-Check-By: sourceware.org
Message-ID: <4AF00CED.2070005@esiee.fr>
Date: Tue, 03 Nov 2009 11:58:53 +0100
From: Laurent Najman <l DOT najman AT esiee DOT fr>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr-FR; rv:1.8.1.21) Gecko/20090403 SeaMonkey/1.1.16
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Parenthood seems to be lost when the parent is exeeced
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

Hi,

The parenthood seems to be lost when the parent is execed.
Here is a sample code

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <windows.h>

int main(int argc, char **argv)
{
  int status;
 
  if (argc > 1)   {
    printf ("Execed Parent: Cygwin: %d Windows: %lu \n",
        getpid (), GetCurrentProcessId ());
    wait(NULL);
    printf("Parent has waited its child\n");
    return 0;
  }
  switch (fork ())   {
  case 0: // Child
    sleep(1);
    printf("Child Cygwin: %d Windows: %lu Parent= %d has ended\n",
       getpid (), GetCurrentProcessId (), getppid());
    break;
  default: // Parent
    printf ("Parent : Cygwin: %d Windows: %lu\n",
        getpid (), GetCurrentProcessId (), getppid());
    execl ("./x", "x", "child", NULL);
    break;
  }
  return 0;
}

Here is the execution of the code

Laurent Najman AT PC4354B /cygdrive/d/src/XXX
$ gcc -o x x.c

Laurent Najman AT PC4354B /cygdrive/d/src/XXX
$ ./x
Parent : Cygwin: 4308 Windows: 5080
Execed Parent: Cygwin: 4308 Windows: 4728
Parent has waited its child

Laurent Najman AT PC4354B /cygdrive/d/src/XXX
$ Child Cygwin: 4784 Windows: 4784 Parent= 1 has ended


Normally, I would expect the parent to be 4308, and I would expect that 
parent to wait for its child.
Is this cygwin behavior a normal behavior?

Thanks in advance,
Laurent Najman


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