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 18:36:14 &#45;0700 -->
<!--X-Message-Id: 19980616183038.28854#divcom,slimy.com -->
<!--X-Content-Type: text/plain -->
<!--X-Reference: 19980616164557.01201#divcom,slimy.com -->
<!--X-Reference: Pine.LNX.3.93.980616180310.10713A&#45;100000#the486,bradley.edu -->
<!--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="msg01090.html">Previous</a>
&nbsp;|&nbsp;<a href="msg01092.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Thread:&nbsp;
[&nbsp;<a href="msg01089.html">Previous</a>
&nbsp;|&nbsp;<a href="msg01092.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Index:&nbsp;
[&nbsp;<A HREF="author.html#01091">Author</A>
&nbsp;|&nbsp;<A HREF="#01091">Date</A>
&nbsp;|&nbsp;<A HREF="thread.html#01091">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 18:30:38 -0700</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 Tue, Jun 16, 1998 at 06:20:53PM -0500, Katrina McClelan wrote:
&gt; On Tue, 16 Jun 1998, Jon Leonard wrote:
&gt; &gt; On Sun, Jun 14, 1998 at 07:57:38AM -0700, J C Lawrence wrote:
&gt; &gt; &gt; Katrina McClelan&lt;kitkat#the486,bradley.edu&gt; wrote:
&gt; &gt; &gt; 
&gt; &gt; &gt; &gt; 	if(!fork()) { /* child copy starts here */
&gt; &gt; &gt; &gt;         kill(getpid(),SIGSEGV); /* this'll dump core */ 
&gt; &gt; &gt; &gt;         sleep(10); /* make sure it stops here */ 
&gt; &gt; &gt; &gt;         /* dead by here */ 
&gt; &gt; &gt; &gt;       }
&gt; &gt; &gt; &gt; 	/* parent continues unaware */
&gt; &gt; &gt; 
&gt; &gt; If I read the code right, the sleep is in the child, to keep the child
&gt; &gt; from executing additional parent code.  I'd include an exit() after the
&gt; &gt; sleep, so that if the kill doesn't work (SIGSEGV blocked?), the child
&gt; &gt; doesn't do any damage.
&gt; 
&gt; This is probably good.... the code I submitted was not meant (in my mind) 
&gt; to be fail safe.  The exit makes sure the child does no damage and is thus
&gt; good.  It's not really elegant, but then how elegant can you be when
&gt; you're trying to dump core ;)?  I assume this is only a tool and not going
&gt; to be a part of the finished server?  Even if it is, Ben can figure out
&gt; how to make it "perfect" from there.  SIGSEGV can be blocked, but
&gt; shouldn't be.  Actually I think the sleep is unneeded since the child
&gt; kills itself which is executed linear, so kill won't return until the
&gt; signal is sent and received thus killing the process in kill().  The exit
&gt; should be used incase kill fails. 

A lot depends on how paranoid the coding is.  It's certainly not necessary
to put all of the debug checking into example code -- it makes it harder
to read, for one thing.  Still, I like to list the things that one might
want to check for or otherwise worry about.

Some programs may trap SIGSEGV for memory management purposes.  Assuming
exacting knowlege of the memory map, you can just assume you have enough
memory, and if you don't, brk() some more.  Icky (breaks malloc, etc.),
but I think "sh" does this...  Basically, if you use a signal to dump core,
make sure it's not also used for something else in the program.

I'm also not completely sure about the signal from kill getting to the
process immediately.  The word "asynchronous" in the man page gives a
lot of freedom to the OS.

&gt; &gt; That said, I'd use abort() instead of kill, and not bother with the sleep.
&gt; &gt; I'd keep the exit() because I'm paranoid, and some older OSes may return
&gt; &gt; from abort.  If the appropriate signal is precise, the sleep is useless
&gt; &gt; anyway.
&gt; 
&gt; This is a better way to go, since abort can't return accd to the man page.

Depends on your man page.  My SunOS system claims it can return if SIGIOT is
caught or ignored.  Portability to SunOS may be a bigger issue to me than
anyone else here, of course.

&gt; &gt; Failure to fork would be good to test for.  If you're willing to accept
&gt; &gt; a failure mode of no core file, the above code is find.  
&gt; 
&gt; I was assuming Ben was looking for just a quick and easy way and that he'd
&gt; add his own error checking.

Quite possibly.  But If I'd included a debugging feature like this in my MUD,
I'd leave it in production code.  Doesn't hurt much, and you never know
when you'll need it, and something might break if you take it out (due to
typos, etc).

The other feature I might add would be the ability to specify a (possibly new)
directory for it to go into.  This would allow multiple core dumps without
worrying about overwriting.

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="01108" HREF="msg01108.html">[MUD-Dev] Re: Technical C/C++ coding question</A></strong>
<ul compact><li><em>From:</em> Shawn Halpenny &lt;malachai#iname,com&gt;</li></ul>
<li><strong><A NAME="01095" HREF="msg01095.html">[MUD-Dev] Re: Technical C/C++ coding question</A></strong>
<ul compact><li><em>From:</em> Ben Greear &lt;greear#cyberhighway,net&gt;</li></ul>
<li><strong><A NAME="01092" HREF="msg01092.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="01088" HREF="msg01088.html">[MUD-Dev] Re: Technical C/C++ coding question</A></STRONG>
<UL><LI><EM>From:</EM> Jon Leonard &lt;jleonard#divcom,slimy.com&gt;</LI></UL></LI>
<LI><STRONG><A NAME="01089" HREF="msg01089.html">[MUD-Dev] Re: Technical C/C++ coding question</A></STRONG>
<UL><LI><EM>From:</EM> Katrina McClelan &lt;kitkat#the486,bradley.edu&gt;</LI></UL></LI>
</UL></LI></UL>
<!--X-References-End-->
<!--X-BotPNI-->
<UL>
<LI>Prev by Date:
<STRONG><A HREF="msg01090.html">[MUD-Dev] Re: Levelless MUDs</A></STRONG>
</LI>
<LI>Next by Date:
<STRONG><A HREF="msg01092.html">[MUD-Dev] Re: Technical C/C++ coding question</A></STRONG>
</LI>
<LI>Prev by thread:
<STRONG><A HREF="msg01089.html">[MUD-Dev] Re: Technical C/C++ coding question</A></STRONG>
</LI>
<LI>Next by thread:
<STRONG><A HREF="msg01092.html">[MUD-Dev] Re: Technical C/C++ coding question</A></STRONG>
</LI>
<LI>Index(es):
<UL>
<LI><A HREF="index.html#01091"><STRONG>Date</STRONG></A></LI>
<LI><A HREF="thread.html#01091"><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: Technical C/C++ coding question</STRONG>, <EM>(continued)</EM>
<ul compact>
<ul compact>
<ul compact>
<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>
<LI><strong><A NAME="01108" HREF="msg01108.html">[MUD-Dev] Re: Technical C/C++ coding question</A></strong>, 
Shawn Halpenny <a href="mailto:malachai#iname,com">malachai#iname,com</a>, Wed 17 Jun 1998, 15:41 GMT
<UL>
<LI><strong><A NAME="01110" HREF="msg01110.html">[MUD-Dev] Re: Technical C/C++ coding question</A></strong>, 
Shawn Halpenny <a href="mailto:malachai#iname,com">malachai#iname,com</a>, Wed 17 Jun 1998, 15:53 GMT
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</ul>
</ul>
</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>