Strange exec behavior

Pierre A. Humblet Pierre.Humblet@ieee.org
Thu Mar 14 12:37:00 GMT 2002


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/


More information about the Cygwin mailing list

AltStyle によって変換されたページ (->オリジナル) /