nativity/test/fork/main.nat
David Gonzalez Martin 347ba162a8 Implement fork
2023-12-02 23:47:49 -06:00

16 lines
418 B
Plaintext

const std = #import("std");
const main = fn() s32 {
if (std.os.duplicate_process()) |pid| {
if (pid == 0) {
std.print(bytes = "Hello from child\n");
std.os.exit(exit_code = 0);
} else {
std.print(bytes = "Hello from parent\n");
return 0;
}
} else {
std.print(bytes = "Unable to create child process\n");
return 1;
}
}