Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forking Memory Errors

Status
Not open for further replies.

CodingFreak

Programmer
Dec 22, 2003
17
US
I am forking a process that has worked before but for some reason now when I run it putting an exit to exit out of the process after I'm done I'm getting a memory access error from windows for the perl.exe. Here is the code:

my ($pid, @pids) = (undef, ());
foreach $name (keys %tella)
{
if ($pid = fork)
{
push @pids, $pid;
}
elsif (defined $pid and $pid == 0)
{
foreach $cmd (sort(keys %commands))
{
&fetchTellabsData($name, $tella{$name},$commands{$cmd});
}
exit;

}
else
{
die "can't fork: $!\n";
}
}

foreach $pid (@pids)
{
waitpid $pid, 0
}

Am I doing something wrong?

CF

An expert is someone who learns more and more about less and less and eventually knows everything about nothing
 
I'm not sure what the problem is. I ran a test code of what you posted. I created a hash, and at the end printed out the pid numbers. From my test, 4 processes should have been spawned, and it printed out 4 pid numbers. Thus, the code works. the exit command in the child process should only exit the child. The error must be coming from somewhere else.
 
It's interesting because when I take the data out to where it's only running against one machine (I have 4 that are in the processes)it will run the whole thing without erroring out at the exit but when I go to two or more machines then I start having the problem. Also when I put an exit at the end of the script it will error out even on one machine.

CF

An expert is someone who learns more and more about less and less and eventually knows everything about nothing
 
What version of Perl?

Latest version has an excellent implementation of fork()

Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
I had to move down to 5.6 due to DBD-Oracle problems I was having. I moved the code to a unix machine and it works fine so I'm assuming it's the windows load. Thanks guys!

CF

An expert is someone who learns more and more about less and less and eventually knows everything about nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top