Skip to content

Instantly share code, notes, and snippets.

@tokuhirom
Created March 12, 2009 15:00
Show Gist options
  • Save tokuhirom/78106 to your computer and use it in GitHub Desktop.
Save tokuhirom/78106 to your computer and use it in GitHub Desktop.
# =========================================================================
# How do you like fork(2)
#
# =========================================================================
use strict;
use warnings;
my $type = shift or die "Usage: $0 type";
love_fork($type);
print "YO!\n";
sub love_fork {
my $type = shift;
my $code = +{
simple => sub {
fork();
},
'open' => sub {
open my $fh, '|-';
},
'syscall' => sub {
require 'syscall.ph';
syscall(&SYS_fork);
},
'IO::File' => sub {
require IO::File;
IO::File->new('|-');
},
dynaloader => sub {
require DynaLoader;
DynaLoader::dl_install_xsub(
"myfork",
DynaLoader::dl_find_symbol(
DynaLoader::dl_load_file("libc.so"),
'fork'
),
);
myfork();
},
}->{$type};
die "unknown type : $type" unless $code;
$code->();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment