Xref: utzoo comp.unix.aux:4716 comp.unix.wizards:25758 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!wuarchive!uunet!ddtisvr.ddtg.com!pechner From: pechner@ddtg.com (Michael Pechner) Newsgroups: comp.unix.aux,comp.unix.wizards Subject: collapsing forks Summary: Fork returns pid to parent then child dies. Keywords: fork aux Message-ID: <1991May24.215945.13707@ddtg.com> Date: 24 May 91 21:59:45 GMT Sender: news@ddtg.com Distribution: usa Organization: DuPont Design Technologies Group Lines: 107 Originator: pechner@mikey.ddtg.com I am having a very strange problem with A/UX. I can cause a fork to "sort of" fail by having a huge automatic variable. Here are two programs to show my point. The only difference between the two programs are that junk is an automatic in the version that fails, and a global static in the version that works. The working program: #include static char junk[256000]; void catch() { printf("signal caught pid %d\n", getpid()); } main(){ int ret; int pip[2]; char buf[3]; printf("pipe call %d\n", pipe(pip)); ret=fork(); printf("fork just occured %d \n", ret); if((ret=fork()) == 0){ /*child */ signal(SIGALRM, catch); alarm(10); printf("return from child write %d\n", write(pip[1], "a", 1)); sleep(2); exit(1); } else if(ret > 0){ /* parent */ signal(SIGALRM, catch); alarm(10); printf("return from parent read %d\n", read (pip[0], buf, 1)); printf("parent read %c\n", buf[0]); sleep(2); exit(1); } } The output: pipe call 0 fork just occured 0 fork just occured 991 return from child write 1 return from parent read 1 parent read a return from child write 1 return from parent read 1 parent read a The non-working program. The only difference is that "junk" is an automatic variable. #include void catch() { printf("signal caught pid %d\n", getpid()); } main(){ int ret; int pip[2]; char buf[3]; char junk[256000]; printf("pipe call %d\n", pipe(pip)); ret=fork(); printf("fork just occured %d \n", ret); if((ret=fork()) == 0){ /*child */ signal(SIGALRM, catch); alarm(10); printf("return from child write %d\n", write(pip[1], "a", 1)); sleep(2); exit(1); } else if(ret > 0){ /* parent */ signal(SIGALRM, catch); alarm(10); printf("return from parent read %d\n", read (pip[0], buf, 1)); printf("parent read %c\n", buf[0]); sleep(2); exit(1); } } The output: pipe call 0 fork just occured 1013 signal caught pid 1011 return from parent read -1 parent read Notice that on the failed call, the fork returns a valid pid to the parent. The child does not return. The child process collapses immediately. Can anybody explain this to me? -- pechner@mikey.ddtg.com (Michael Pechner) | Pizza Probably The Worlds Most DuPont Design Technologies Group | Perfect Food. Santa Clara, Ca | Carbo, Meat, Dairy, And Veggie | All Food Groups In One.