Re: optimize log parsing
- From: "it_says_BALLS_on_your forehead" <simon.chao@xxxxxxx>
- Date: 5 Oct 2005 11:30:22 -0700
Hey Xho, I tried this:
----
#!/apps/webstats/bin/perl
use File::Copy;
use Parallel::ForkManager;
my $pm = Parallel::ForkManager->new(5);
$pm->run_on_start(
sub { my ($pid,$ident)=@_;
print "** $ident started, pid: $pid\n";
}
);
my @data = 1 ... shift;
for (@data) {
my $pid = $pm->start and next;
print "$pid: $_\n";
$pm->finish;
}
$pm->wait_all_children;
------------
and got this:
#####
[smro180 123] ~/simon/1-perl > tryFork.pl 10
** started, pid: 16208
0: 1
** started, pid: 16209
0: 2
** started, pid: 16210
0: 3
** started, pid: 16211
0: 4
** started, pid: 16212
0: 5
** started, pid: 16213
0: 6
** started, pid: 16214
0: 7
** started, pid: 16215
0: 8
** started, pid: 16216
0: 9
** started, pid: 16217
0: 10
[smro180 124] ~/simon/1-perl >
####
....I read this:
start [ $process_identifier ]
This method does the fork. It returns the pid of the child process for
the parent, and 0 for the child process. If the $processes parameter
for the constructor is 0 then, assuming you're in the child process,
$pm->start simply returns 0.
An optional $process_identifier can be provided to this method... It is
used by the "run_on_finish" callback (see CALLBACKS) for identifying
the finished process.
and this:
run_on_start $code
You can define a subroutine which is called when a child is started. It
called after the successful startup of a child in the parent process.
The parameters of the $code are the following:
- pid of the process which has been started
- identification of the process (if provided in the "start" method)
....but I don't understand why in my: print "$pid: $_\n";
line, i'm getting 0 as the pid. I know the documentation said i should
get 0 for the child process and the child pid for the parent, but
aren't i calling start on the parent? and in the callback, why are
there more than 5 different process ids?
.
- Follow-Ups:
- Re: optimize log parsing
- From: xhoster
- Re: optimize log parsing
- From: it_says_BALLS_on_your forehead
- Re: optimize log parsing
- References:
- optimize log parsing
- From: it_says_BALLS_on_your forehead
- Re: optimize log parsing
- From: it_says_BALLS_on_your forehead
- Re: optimize log parsing
- From: Tassilo v. Parseval
- Re: optimize log parsing
- From: it_says_BALLS_on_your forehead
- Re: optimize log parsing
- From: xhoster
- optimize log parsing
- Prev by Date: Re: Sorting a nested array (table) (alphabetically)
- Next by Date: Re: optimize log parsing
- Previous by thread: Re: optimize log parsing
- Next by thread: Re: optimize log parsing
- Index(es):
Relevant Pages
|