Created
March 28, 2011 06:38
-
-
Save lopnor/890083 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
#!perl6 | |
use v6; | |
sub fork { | |
my $pid = Q:PIR{ | |
.include 'sysinfo.pasm' | |
.local string info, libname | |
.local pmc fork, pid | |
pid = new ['Integer'] | |
info = sysinfo .SYSINFO_PARROT_OS | |
if info == 'darwin' goto DARWIN | |
if info == 'linux' goto LINUX | |
branch END | |
DARWIN: | |
libname = 'libc' | |
branch FORK | |
LINUX: | |
null libname | |
branch FORK | |
FORK: | |
$P0 = loadlib libname | |
fork = dlfunc $P0, 'fork', 'i' | |
pid = fork() | |
END: | |
%r = pid | |
}; | |
return $pid; | |
} | |
my $pid = fork; | |
if ($pid) { | |
say 'parent'; | |
} else { | |
say 'child'; | |
} | |
# vim: ft=perl6 : |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment