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; }
Tom Melly, pm (at) cursingmaggot (stop) co (stop) ukmap{$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
In reply to Kill a child nicely by Melly
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |