[Home] [Groups] - Message: [Prev in Group] [Next in Group]
5782: [MUD-Dev] Re: Technical C/C++ coding question
[Full Header] [Plain Text]
From: J C Lawrence <claw@kanga.nu>
Newsgroups: nu.kanga.list.mud-dev
Date: Sun, 14 Jun 1998 07:57:38 -0700
References: [1]
Organization: Kanga.Nu
On Sun, 14 Jun 1998 00:39:06 -0500 (CDT)
Katrina McClelan<kitkat@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@null.net
----------(*) Internet: coder@ibm.net
...Honourary Member of Clan McFud -- Teamer's Avenging Monolith...