Skip to content

Instantly share code, notes, and snippets.

@edgarcosta
Created May 14, 2024 20:35
Show Gist options
  • Save edgarcosta/0a2520d3efebd7357f4493a13383ebf1 to your computer and use it in GitHub Desktop.
Save edgarcosta/0a2520d3efebd7357f4493a13383ebf1 to your computer and use it in GitHub Desktop.
function MultiFork(n)
parentpid := Getpid();
IsParentProcess := func<|parentpid eq Getpid()>;
res := [];
for i in [1..n] do
if IsParentProcess() then
Append(~res, Fork());
if not IsParentProcess() then
return [], i;
end if;
end if;
end for;
return res, 0;
end function;
b, r := MultiFork(10);
print b, r;
if r ne 0 then
exit 0;
end if;
// If you remove this comment, everything goes as expected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment