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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Apache2 and Forks

Status
Not open for further replies.

Scalius

Programmer
Joined
Sep 16, 2005
Messages
3
Location
PT
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>
';
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top