Hello,
i am a beginner to perl programming and i'm having a strange problem that i don't understand and i'm hoping someone can't help me.
My problem is that i created a script in perl that uses forks (Parallel::ForkManager).
The script is really simple, i just need each of the forks to write one value into one file and in the end the parent process will read it.
The problem is that when i run the script using the shell everything work fine. But if run it through the web browser the script stops after all the children processes die.
I don't understand why the parent process is not continued after.
the code i'm using is bellow.
Thank you.
#!/usr/bin/perl
use warnings;
use strict;
use Parallel::ForkManager;
my $pm = new Parallel::ForkManager(30);
my $i = 0;
my $tmp_value = 0;
print "Content-type: text/html\n\n";
print '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "<html>
<head>
<title>Get Counters QoS</title>
</head>
<body bgcolor="#99FFFF">
';
for ($i=0;$i<20;$i++) {
$pm->start and next;
open (FILE_DATA, ">> /var/ flock(FILE_DATA,LOCK_EX);
print FILE_DATA "$i\n";
close(FILE_DATA);
$pm->finish;
}
$pm->wait_all_children;
open (FILE_DATA, "< /var/ flock(FILE_DATA,LOCK_EX);
while ($tmp_value = <FILE_DATA>) {
print "$tmp_value\n";
}
close(FILE_DATA);
print '
</body>
</html>
';
i am a beginner to perl programming and i'm having a strange problem that i don't understand and i'm hoping someone can't help me.
My problem is that i created a script in perl that uses forks (Parallel::ForkManager).
The script is really simple, i just need each of the forks to write one value into one file and in the end the parent process will read it.
The problem is that when i run the script using the shell everything work fine. But if run it through the web browser the script stops after all the children processes die.
I don't understand why the parent process is not continued after.
the code i'm using is bellow.
Thank you.
#!/usr/bin/perl
use warnings;
use strict;
use Parallel::ForkManager;
my $pm = new Parallel::ForkManager(30);
my $i = 0;
my $tmp_value = 0;
print "Content-type: text/html\n\n";
print '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "<html>
<head>
<title>Get Counters QoS</title>
</head>
<body bgcolor="#99FFFF">
';
for ($i=0;$i<20;$i++) {
$pm->start and next;
open (FILE_DATA, ">> /var/ flock(FILE_DATA,LOCK_EX);
print FILE_DATA "$i\n";
close(FILE_DATA);
$pm->finish;
}
$pm->wait_all_children;
open (FILE_DATA, "< /var/ flock(FILE_DATA,LOCK_EX);
while ($tmp_value = <FILE_DATA>) {
print "$tmp_value\n";
}
close(FILE_DATA);
print '
</body>
</html>
';