Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.


In reply to Re: Problem with signal handler by jbert
in thread Problem with signal handler by LH2007

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-24 22:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found