[MUD-Dev] Re: Technical C/C++ coding question

J C Lawrence claw at kanga.nu
Sun Jun 14 07:57:38 CEST 1998


On Sun, 14 Jun 1998 00:39:06 -0500 (CDT) 
Katrina McClelan<kitkat at the486.bradley.edu> wrote:

> 	if(!fork()) { /* child copy starts here */
>         kill(getpid(),SIGSEGV); /* this'll dump core */ 
>         sleep(10); /* make sure it stops here */ 
>         /* dead by here */ 
>       }
> 	/* parent continues unaware */

  1) No, you are not even slightly guaranteed that the child will have
fully exited/cored by the end of the sleep.  Process schedulers are
funny that way.  Call waitpid().  Be prepared for the child to have
already exited and to have left the process table by the time
waitpid() is run in the parent (WNOWAIT).  

  2) Check for failure of the fork() and retry if needed.  On
healthily running systems, fork() may well fail due to contention at
the process table spinlock.  The Kernel will throw an error rather
than queue the requests and guarantee success (common design decision
for SMP kernels).  You should account for this.  

  3) You'd get slightly cleaner results if the child just immediately
hung an alarm() and the parent killed the child.

--
J C Lawrence                               Internet: claw at null.net
----------(*)                              Internet: coder at ibm.net
...Honourary Member of Clan McFud -- Teamer's Avenging Monolith...




More information about the mud-dev-archive mailing list