Created
March 12, 2009 15:00
-
-
Save tokuhirom/78106 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ========================================================================= | |
# 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