Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: How to run the child process parellel to the parent process with fork

by bojinlund (Parson)
on Mar 15, 2013 at 23:04 UTC ( #1023792=note: print w/replies, xml ) Need Help??


in reply to How to run the child process parellel to the parent process with fork

This shows two other alternatives of parallel processing (not explicitly using fork). Save this as MyChameleon.pm:

package MyChameleon; use strict; use warnings; use threads; $| = 1; # autoflush STDOUT my $used_as_script = not caller(); if ($used_as_script) { print "Start script\n"; my $thread_to_do = threads->create( \&to_do, 'thread', 5 ); my $thread_sys = threads->create( sub { system $^X, "-MMyChameleon", "-e", "MyChameleon::to_do('sy +stem')"; } ); to_do( 'script', 3 ); $thread_to_do->join; $thread_sys->join; exit; } sub to_do { my ( $tag, $times ) = @_; $times //= 10; print "$tag: Hello World!\n"; map { print "$tag ($_)\n"; sleep 1 } ( 1 .. $times ); print "$tag: is done\n"; } !!1;

Run it like this: “perl MyChameleon.pm”.

See also How a script becomes a module

  • Comment on Re: How to run the child process parellel to the parent process with fork
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1023792]
help
Chatterbox?
[stevieb]: heh, yeah, sorry. This is integration testing for certain. In fact, it's even Continuous Integration ;)
[stevieb]: Obviously, Travis CI just won't cut it for these distributions...
[stevieb]: I went on my merry way writing a cross-platform, network-aware system that works across Perlbrew and Berrybrew systems and runs unit tests for Perl dists on all installed versions, with the ability to manage *brew commands themselves
[stevieb]: That worked out exceptionally well, as when I started that project, I hadn't delved into hardware development yet.

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2017-06-25 23:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (572 votes). Check out past polls.