C
christoph.rabel
Hi!
I have inherited a server application which was moved to Linux a
couple of weeks ago. Now we see a lot of defunct processes in the
process list.
Essentially we spawn a new thread for each client. communicate "talks"
a while with it and closes the connection afterwards. As it seems, the
spawned processes end up as zombies. Can I avoid this behavior easily?
Or is ignoring it the best approach?
Here is some code to illustrate our approach:
(I simplified it slightly, removed some error checking)
while (($paddr = accept(CLIENT, SERVER)) || !$time_to_die) {
if ($paddr) {
my ($port, $iaddr) = sockaddr_in($paddr);
my $name = gethostbyaddr($iaddr, AF_INET);
my $ip = inet_ntoa($iaddr);
logMsg(2, $ip . "(" . $name . "):" . $port . "
connected");
spawn (sub {
communicate($ip, $port);
});
}
}
I have inherited a server application which was moved to Linux a
couple of weeks ago. Now we see a lot of defunct processes in the
process list.
Essentially we spawn a new thread for each client. communicate "talks"
a while with it and closes the connection afterwards. As it seems, the
spawned processes end up as zombies. Can I avoid this behavior easily?
Or is ignoring it the best approach?
Here is some code to illustrate our approach:
(I simplified it slightly, removed some error checking)
while (($paddr = accept(CLIENT, SERVER)) || !$time_to_die) {
if ($paddr) {
my ($port, $iaddr) = sockaddr_in($paddr);
my $name = gethostbyaddr($iaddr, AF_INET);
my $ip = inet_ntoa($iaddr);
logMsg(2, $ip . "(" . $name . "):" . $port . "
connected");
spawn (sub {
communicate($ip, $port);
});
}
}