Subject: Odd fork behavior- W95/b16
From: [email-masked] (Matthew Moskewicz)

22 Oct 1996 01:22:27 -0700
Sender: [email-masked]
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Mozilla 3.01b1Gold (Win95; I)
Original-To: [email-masked]
Original-Sender: [email-masked]

I'm running Win95 (w/ serv pack 1) and b16. I've been off the list for a
while, so I'm not sure if this issue has been brought up already. I
tried to wade through the fork source myself for a while, but it is
beyond me in its win32 complexities, though the setjmp stuff looks
suspicious. 

I've been seeing some odd behavior when (attempting) to use fork().
Namly, if the parent ends while a child is active, an exception is
generated to the parent stderr, referencing the child PID (see output).
This exception seems to hang the child. That is, I can see the child
listed with ps, but it is apparently hung, and is unkillable.

Another error I get, but which I can not reporduce in a short program,
occured when I compiled apache. It complains that:

BIGCOW:~/local/etc/httpd/src>httpd
Attempting to fork... <-- I added this
httpd: unable to fork new process
fork: No such file or directory

Rearanging the code randomly (moving the fork call in or out of
functions, before or after other random statements) sometimes allows
fork() to work, though this is very hard to reproduce, but then I run
into the Parent dies before child exception. As a side note, apache
almost runs with the -X option (single process) but it only serves the
first 1k or so of every document that is requested.

Final note: If the child dies first, all goes as would be expected, with
no errors.

Here is forker.c and it's output:
[forker.c]
#include<stdio.h>
#include<unistd.h>
#include<setjmp.h>

void dofork(void);

int main (void )
{
  dofork();
  return 0;
}

void dofork(void)
{
  int i;
  i = fork();
  printf ("Fork got: %i\n",i);
  if (i < 0)
  {
    printf("Fork failed.\n");
  }
  if (i > 0)
  {
    printf("Fork okay.\n");
    sleep(2);
    printf("Parent end.\n");
    exit(0);
  }
  sleep(3);
  printf("Child Alive after Parent Dies.\n");
  sleep(1);
  printf ("Child End.\n");
  exit (0);
  return;
}

[output]
Fork got: 1006
Fork okay.
Fork got: 0 <-- From child Process
Parent end.
(forker.exe 1006) In cygwin_except_handler
(forker.exe 1006) Exception trapped!
(forker.exe 1006) exception C0000005 at BFF784F0
(forker.exe 1006) exception: ax 63EFB4 bx 39 cx 77083A dx 833E227C
(forker.exe 1006) exception: si 36 di 63EFE4 bp 63EFB8 sp 63EF8C
(forker.exe 1006) exception is: STATUS_ACCESS_VIOLATION
(forker.exe 1006) Stack trace:
(forker.exe 1006) frame 0: sp = 0x63EDA4, pc = 0x10002A68
(forker.exe 1006) frame 1: sp = 0x63EDC0, pc = 0xBFF7663C
(forker.exe 1006) frame 2: sp = 0x63EDE4, pc = 0xBFF859D9
(forker.exe 1006) frame 3: sp = 0x63EE7C, pc = 0xFFECBAD7
(forker.exe 1006) frame 4: sp = 0x63EFB8, pc = 0x10003C95
(forker.exe 1006) frame 5: sp = 0x63F3E4, pc = 0x10012432
(forker.exe 1006) frame 6: sp = 0x63F40C, pc = 0x100221FF
(forker.exe 1006) frame 7: sp = 0x63F424, pc = 0x10020DA2
(forker.exe 1006) frame 8: sp = 0x63F440, pc = 0x10017986
(forker.exe 1006) frame 9: sp = 0x63F460, pc = 0x10020E2B
(forker.exe 1006) frame 10: sp = 0x63F47C, pc = 0x1001ED9C
(forker.exe 1006) frame 11: sp = 0x63F48C, pc = 0x10017778
(forker.exe 1006) frame 12: sp = 0x63F4A0, pc = 0x401129
(forker.exe 1006) frame 13: sp = 0x63F4B0, pc = 0x401021
(forker.exe 1006) frame 14: sp = 0x63F4B8, pc = 0x10001EBB
(forker.exe 1006) frame 15: sp = 0x63FE14, pc = 0x10001ECF
(forker.exe 1006) End of stack trace (more stack frames may be present)
[Note that "Child alive after parent dies." is *not* printed]

[after the fact, child is hung]
BIGCOW:~/proj> ps
     PID     PPID  WIN32-PID   UID  COMMAND
    1000     1000    -306647   500  C:\bin\sh.exe
    1015     1000    -318795   500  c:\USR\H-I386-CYGWIN32\BIN\ps.exe
     1006     1005    -314743   500  forker.exe
   
BIGCOW:~/proj>kill 1006
Kill 1006
killing 1006 (win32 pid -314743)
Error opening 1006 (win32 -314743)
-
For help on using this list, send a message to
"[email-masked]" with one line of text: "help".