delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/03/14/15:20:49

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <3C9105D1.9463CCAB@ieee.org>
Date: Thu, 14 Mar 2002 15:19:29 -0500
From: "Pierre A. Humblet" <Pierre DOT Humblet AT ieee DOT org>
X-Mailer: Mozilla 4.73 [en] (WinNT; U)
X-Accept-Language: en,pdf
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Strange exec behavior

Is this normal?                     [ please cc: me directly]
~> ps -W | fgrep /a
      506       1     345        430    3 11054 13:49:15 /h/a
      506       1     345        430    3 11054 13:49:15 /h/a
      506       1     345        430    3 11054 13:49:15 /h/a
      506       1     345        430    3 11054 13:49:15 /h/a
      506       1     345        430    3 11054 13:49:15 /h/a
      506       1     345        430    3 11054 13:49:15 /h/a
      506       1     345        430    3 11054 13:49:15 /h/a
      506       1     345        430    3 11054 13:49:15 /h/a
      506       1     345        430    3 11054 13:49:15 /h/a
      506       1     345        430    3 11054 13:49:15 /h/a
      506       1     345        430    3 11054 13:49:15 /h/a
[Incidentally the WINPIDs are reported incorrectly, but that's
 a side issue ]

The previous situation happens when a process with ppid == 1 
execs itself repeatedly (see demo code below). All the old 
processes stay around.

I have looked at spawn.cc and "how-spawn-works". I understand that
the old process wants to stay around when the child isn't
a Cygwin process.

Spawn.cc
      int nwait = 3;
      HANDLE waitbuf[3] = {pi.hProcess, signal_arrived, spr};
      for (int i = 0; i < 100; i++)
	{
	  switch (WaitForMultipleObjects (nwait, waitbuf, FALSE, INFINITE))
	    {
	    case WAIT_OBJECT_0:
	      sigproc_printf ("subprocess exited");
	      DWORD exitcode;
	      if (!GetExitCodeProcess (pi.hProcess, &exitcode))
		exitcode = 1;
	      res |= exitcode;
	      exited = TRUE;
	      break;
	    case WAIT_OBJECT_0 + 1:
	      sigproc_printf ("signal arrived");
	      reset_signal_arrived ();
	      continue;
	    case WAIT_OBJECT_0 + 2:
	      if (myself->ppid_handle)
		res |= EXIT_REPARENTING;
	      if (!my_parent_is_alive ())
		{
		  nwait = 2;
		  sigproc_terminate ();
		  continue;
		}
When a Cygwin process is launched there should be an event on 
spr, leading to case WAIT_OBJECT_0 + 2:
Even though the child is Cygwin, if myself->ppid_handle == NULL
(all) the parent(s) continue and stay(s) around until the final
descendant exits. What's the a reason for this behavior?

Pierre
**************************************************************
#include <unistd.h>
#include <stdio.h>

main (int argc, char * argv[])
{
	char count[10];
	int i;
	if (getppid() != 1) 
		if (fork() != 0) exit(0); /* parent exits */
	/* Now execs 10 times */
	if (argc == 1) i = 0;
	else i = atoi(argv[1]);
	sprintf(count, "%d", i+1);
	if (i < 10)
		execl(argv[0], argv[0], count, 0);
	sleep(180);
}

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

- Raw text -


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