Hi Monkeys

I'm messing around with sockets, and all is well, but my socket server spends most of its time waiting on "my $live_socket = $socket->accept();".

Up until now, I've just been killing it with ^C, but running the bulk of the socket code as a child process seemed a better way to control it.

My problem is that ideally, I want my parent process to terminate the child, but only if it's sitting on $socket->accept(). Suggestions? Cut-down code below...

my $fork_pid = fork(); if($fork_pid == 0){ while(1){ my $live_socket = $socket->accept(); # only allow parent to kill c +hild here <do stuff - read from socket, checksum check, write to file, send +ACK/NAK etc.> $live_socket->close(); } } # parent should kill child nicely (9 is a bit drastic, but <9 doesn't +seem to work), and only if child is waiting for a socket connection else{ print "Hit <ENTER> to quit\n"; my $quit = <STDIN>; kill 9, $fork_pid; }
map{$a=1-$_/10;map{$d=$a;$e=$b=$_/20-2;map{($d,$e)=(2*$d*$e+$a,$e**2 -$d**2+$b);$c=$d**2+$e**2>4?$d=8:_}1..50;print$c}0..59;print$/}0..20
Tom Melly, pm (at) cursingmaggot (stop) co (stop) uk

In reply to Kill a child nicely by Melly

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.