Hi guys! I need some advice on how to close a socket handle on a child process, I have a daemon which accepts new connections and forks off a child process to handle them. I need communication to be bidirectional, so I've tried forking again to have the parent listening and the child writing to the same socket. The listening parent is just used to listen for a command to stop the connection which kills the child process but the socket associated with it keeps sending. So to sum up after a socket is accepted on the child it calls the client connect method and forks again (code shown below)
sub client_connect { my($connection) = @_; my $kidpid; die "can't fork: $!" unless defined($kidpid = fork()); if ($kidpid) { # parent copies the socket to standard output while (<$connection>) { last if /Close_Server/; } kill("TERM" => $kidpid); # send SIGTERM to child + } else { while (1) { print $connection "some output\n"; } continue { sleep 10; } } }
In reply to Closing socket handle of child process by paulc1976
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |