Skip to content

Instantly share code, notes, and snippets.

@lopnor
Created March 28, 2011 06:38
Show Gist options
  • Save lopnor/890083 to your computer and use it in GitHub Desktop.
Save lopnor/890083 to your computer and use it in GitHub Desktop.
#!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