1998Q2/
<!-- MHonArc v2.4.4 -->
<!--X-Subject: [MUD&#45;Dev] Re: Technical C/C++ coding question -->
<!--X-From-R13: Xba Zrbaneq <wyrbaneqNqvipbz.fyvzl.pbz> -->
<!--X-Date: Tue, 16 Jun 1998 16:52:15 &#45;0700 -->
<!--X-Message-Id: 19980616164557.01201#divcom,slimy.com -->
<!--X-Content-Type: text/plain -->
<!--X-Reference: kitkat#the486,bradley.edu -->
<!--X-Reference: E0ylEE3&#45;0007Cc&#45;00#mail,kanga.nu -->
<!--X-Head-End-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>MUD-Dev message, [MUD-Dev] Re: Technical C/C++ coding question</title>
<!-- meta name="robots" content="noindex,nofollow" -->
<link rev="made" href="mailto:jleonard#divcom,slimy.com">
</head>
<body background="/backgrounds/paperback.gif" bgcolor="#ffffff"
      text="#000000" link="#0000FF" alink="#FF0000" vlink="#006000">

  <font size="+4" color="#804040">
    <strong><em>MUD-Dev<br>mailing list archive</em></strong>
  </font>
      
<br>
[&nbsp;<a href="../">Other Periods</a>
&nbsp;|&nbsp;<a href="../../">Other mailing lists</a>
&nbsp;|&nbsp;<a href="/search.php3">Search</a>
&nbsp;]
<br clear=all><hr>
<!--X-Body-Begin-->
<!--X-User-Header-->
<!--X-User-Header-End-->
<!--X-TopPNI-->

Date:&nbsp;
[&nbsp;<a href="msg01087.html">Previous</a>
&nbsp;|&nbsp;<a href="msg01089.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Thread:&nbsp;
[&nbsp;<a href="msg01034.html">Previous</a>
&nbsp;|&nbsp;<a href="msg01089.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Index:&nbsp;
[&nbsp;<A HREF="author.html#01088">Author</A>
&nbsp;|&nbsp;<A HREF="#01088">Date</A>
&nbsp;|&nbsp;<A HREF="thread.html#01088">Thread</A>
&nbsp;]

<!--X-TopPNI-End-->
<!--X-MsgBody-->
<!--X-Subject-Header-Begin-->
<H1>[MUD-Dev] Re: Technical C/C++ coding question</H1>
<HR>
<!--X-Subject-Header-End-->
<!--X-Head-of-Message-->
<UL>
<LI><em>To</em>: <A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A></LI>
<LI><em>Subject</em>: [MUD-Dev] Re: Technical C/C++ coding question</LI>
<LI><em>From</em>: Jon Leonard &lt;<A HREF="mailto:jleonard#divcom,slimy.com">jleonard#divcom,slimy.com</A>&gt;</LI>
<LI><em>Date</em>: Tue, 16 Jun 1998 16:45:57 -0700</LI>
<LI><em>Cc</em>: Jon Leonard &lt;<A HREF="mailto:jleonard#divcom,slimy.com">jleonard#divcom,slimy.com</A>&gt;</LI>
<LI><em>Reply-To</em>: <A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A></LI>
</UL>
<!--X-Head-of-Message-End-->
<!--X-Head-Body-Sep-Begin-->
<HR>
<!--X-Head-Body-Sep-End-->
<!--X-Body-of-Message-->
<PRE>
On Sun, Jun 14, 1998 at 07:57:38AM -0700, J C Lawrence wrote:
&gt; On Sun, 14 Jun 1998 00:39:06 -0500 (CDT) 
&gt; Katrina McClelan&lt;kitkat#the486,bradley.edu&gt; wrote:
&gt; 
&gt; &gt; 	if(!fork()) { /* child copy starts here */
&gt; &gt;         kill(getpid(),SIGSEGV); /* this'll dump core */ 
&gt; &gt;         sleep(10); /* make sure it stops here */ 
&gt; &gt;         /* dead by here */ 
&gt; &gt;       }
&gt; &gt; 	/* parent continues unaware */
&gt; 
&gt;   1) No, you are not even slightly guaranteed that the child will have
&gt; fully exited/cored by the end of the sleep.  Process schedulers are
&gt; funny that way.  Call waitpid().  Be prepared for the child to have
&gt; already exited and to have left the process table by the time
&gt; waitpid() is run in the parent (WNOWAIT).  

If I read the code right, the sleep is in the child, to keep the child
from executing additional parent code.  I'd include an exit() after the
sleep, so that if the kill doesn't work (SIGSEGV blocked?), the child
doesn't do any damage.

That said, I'd use abort() instead of kill, and not bother with the sleep.
I'd keep the exit() because I'm paranoid, and some older OSes may return
from abort.  If the appropriate signal is precise, the sleep is useless
anyway.

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

Failure to fork would be good to test for.  If you're willing to accept
a failure mode of no core file, the above code is find.  If not, you
should deal with core dump size limits, trapped signals, and current
directory issues.

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

I don't see any particular reason to do this.  It seems cleaner to me
to have the parent do nothing but the fork.

Jon Leonard


</PRE>

<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<HR>
<ul compact><li><strong>Follow-Ups</strong>:
<ul>
<li><strong><A NAME="01089" HREF="msg01089.html">[MUD-Dev] Re: Technical C/C++ coding question</A></strong>
<ul compact><li><em>From:</em> Katrina McClelan &lt;kitkat#the486,bradley.edu&gt;</li></ul>
</UL></LI></UL>
<!--X-Follow-Ups-End-->
<!--X-References-->
<UL><LI><STRONG>References</STRONG>:
<UL>
<LI><STRONG><A NAME="01034" HREF="msg01034.html">[MUD-Dev] Re: Technical C/C++ coding question</A></STRONG>
<UL><LI><EM>From:</EM> J C Lawrence &lt;claw#kanga,nu&gt;</LI></UL></LI>
</UL></LI></UL>
<!--X-References-End-->
<!--X-BotPNI-->
<UL>
<LI>Prev by Date:
<STRONG><A HREF="msg01087.html">[MUD-Dev] Re: Levelless MUDs</A></STRONG>
</LI>
<LI>Next by Date:
<STRONG><A HREF="msg01089.html">[MUD-Dev] Re: Technical C/C++ coding question</A></STRONG>
</LI>
<LI>Prev by thread:
<STRONG><A HREF="msg01034.html">[MUD-Dev] Re: Technical C/C++ coding question</A></STRONG>
</LI>
<LI>Next by thread:
<STRONG><A HREF="msg01089.html">[MUD-Dev] Re: Technical C/C++ coding question</A></STRONG>
</LI>
<LI>Index(es):
<UL>
<LI><A HREF="index.html#01088"><STRONG>Date</STRONG></A></LI>
<LI><A HREF="thread.html#01088"><STRONG>Thread</STRONG></A></LI>
</UL>
</LI>
</UL>

<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
<ul><li>Thread context:
<BLOCKQUOTE><UL>
<LI><STRONG>[MUD-Dev] Re: Off topic! But please help</STRONG>, <EM>(continued)</EM>
<ul compact>
<LI><strong><A NAME="01020" HREF="msg01020.html">[MUD-Dev] Re: Off topic! But please help</A></strong>, 
John Bertoglio <a href="mailto:alexb#internetcds,com">alexb#internetcds,com</a>, Sun 14 Jun 1998, 05:09 GMT
<UL>
<LI><strong><A NAME="01021" HREF="msg01021.html">[MUD-Dev] Technical C/C++ coding question</A></strong>, 
Ben Greear <a href="mailto:greear#cyberhighway,net">greear#cyberhighway,net</a>, Sun 14 Jun 1998, 05:45 GMT
<UL>
<LI><strong><A NAME="01023" HREF="msg01023.html">[MUD-Dev] Re: Technical C/C++ coding question</A></strong>, 
Katrina McClelan <a href="mailto:kitkat#the486,bradley.edu">kitkat#the486,bradley.edu</a>, Sun 14 Jun 1998, 06:52 GMT
<UL>
<LI><strong><A NAME="01034" HREF="msg01034.html">[MUD-Dev] Re: Technical C/C++ coding question</A></strong>, 
J C Lawrence <a href="mailto:claw#kanga,nu">claw#kanga,nu</a>, Sun 14 Jun 1998, 14:57 GMT
<UL>
<LI><strong><A NAME="01088" HREF="msg01088.html">[MUD-Dev] Re: Technical C/C++ coding question</A></strong>, 
Jon Leonard <a href="mailto:jleonard#divcom,slimy.com">jleonard#divcom,slimy.com</a>, Tue 16 Jun 1998, 23:52 GMT
<UL>
<LI><strong><A NAME="01089" HREF="msg01089.html">[MUD-Dev] Re: Technical C/C++ coding question</A></strong>, 
Katrina McClelan <a href="mailto:kitkat#the486,bradley.edu">kitkat#the486,bradley.edu</a>, Wed 17 Jun 1998, 00:34 GMT
<UL>
<LI><strong><A NAME="01091" HREF="msg01091.html">[MUD-Dev] Re: Technical C/C++ coding question</A></strong>, 
Jon Leonard <a href="mailto:jleonard#divcom,slimy.com">jleonard#divcom,slimy.com</a>, Wed 17 Jun 1998, 01:36 GMT
<UL>
<LI><strong><A NAME="01092" HREF="msg01092.html">[MUD-Dev] Re: Technical C/C++ coding question</A></strong>, 
Katrina McClelan <a href="mailto:kitkat#the486,bradley.edu">kitkat#the486,bradley.edu</a>, Wed 17 Jun 1998, 01:50 GMT
</LI>
<LI><strong><A NAME="01095" HREF="msg01095.html">[MUD-Dev] Re: Technical C/C++ coding question</A></strong>, 
Ben Greear <a href="mailto:greear#cyberhighway,net">greear#cyberhighway,net</a>, Wed 17 Jun 1998, 03:00 GMT
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</ul>
</LI>
</UL></BLOCKQUOTE>

</ul>
<hr>
<center>
[&nbsp;<a href="../">Other Periods</a>
&nbsp;|&nbsp;<a href="../../">Other mailing lists</a>
&nbsp;|&nbsp;<a href="/search.php3">Search</a>
&nbsp;]
</center>
<hr>
</body>
</html>