PDA

View Full Version : Forking Problems


marting
12-19-2002, 01:07 PM
Hi All,
I've written a script which looped through a list of platforms and during each iteration I needed to create a bi-directional socket, to achieve this I forked the process, used the child to send on the socket and used the parent to listen. This all works fine when I have only one platform to update but when I loop through this process again I haven't got any mechanism to prevent the new child from creating a child of its own.

When I had to update multiple platforms I ended up consuming all my resources as I continued to create new forks. Is there any way to destroy the fork or to prevent the child from creating another one ?

Any Help would be greatly appreciated

Here is a sample of the code.

for (my $Platcount = 0; $Platcount < $Arrsize; $Platcount++)

{
my $SMSC = pop(@platList);
$socket = IO::Socket::INET->new
(
PeerAddr => $SMSC,
PeerPort => 17500,
Proto => "tcp",
Type => SOCK_STREAM
) or die "Could not Create Client. \n";

unless (defined($child_pid = fork())) {die "Can't Fork Process.\n"};

$/="";
$Message = <PROVFILE>;

if($child_pid)
{
print $socket $Message;
}
else
{
while ($readline = <$socket>)
{
print LOGFILE $readline;
}
}

}