You're nearly there.
You're not setting your child signal handler until after the loop has finished. Set it before the loop (just as soon as you know you're the child) and you'll see the message you're expecting.
Some additional notes:
- You're setting the parent signal handler every time around the loop. You only need to set it once, when you know you are the parent.
- You probably don't need to propogate the signal from the parent to the child with a 'kill', since a ctrl-C is normally sent to all processes in a process group. The shell creates a process group for each command, which will be inherited by all forked processes (unless you call setpgrp to change it). Note that for other signals in other environments you may need the code you have to 're-kill'.
- You don't have strict and warnings on. It's not hiding a problem in this case, but you should always have them on, particularly to check your code before asking someone else about it.
Edit: I missed the actual question. D'oh. Thanks for answering below.
Of course, if the poster wants to kill both parent and child, it's possible that no signal handling code is necessary at all. a ctrl-C from the shell should send a SIGINT to the process group, giving that behaviour by default.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|