Skip to content

Instantly share code, notes, and snippets.

@issm
Created March 8, 2013 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save issm/5116775 to your computer and use it in GitHub Desktop.
Save issm/5116775 to your computer and use it in GitHub Desktop.
use 5.12.0;
use warnings;
use Getopt::Long;
use Data::Section::Simple qw/get_data_section/;
use Time::HiRes ();
my %opts = ( n => 10 );
GetOptions( 'n=i' => \$opts{n} );
sub foo {
my $id = shift;
( my $text = get_data_section('hoge') || 'FAILED' ) =~ s/\n*$/\n/;;
printf '%02d: %s', $id, $text;
}
sub main {
my $pid0 = $$;
my $id;
for my $i ( 1 .. $opts{n} ) {
my $pid = fork();
$id = $i;
last if ! $pid;
}
if ( $$ == $pid0 ) {
sleep 1;
}
else {
Time::HiRes::sleep ( rand() / 100 );
foo($id);
}
}
main();
__DATA__
@@ hoge
foo bar baz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment