2024-02-27 10:58:05 -06:00

22 lines
648 B
Plaintext

const std = #import("std");
const Error = error{
unexpected_result,
};
const main = fn() Error!void {
if (std.os.duplicate_process()) |pid| {
if (pid == 0) {
std.print(bytes = "Hello from child\n");
const argv = [_:null] ?[&:0]const u8{"/usr/bin/ls"};
_ = std.os.execute(path = "/usr/bin/ls", argv = argv.&, env = std.start.environment_values);
return Error.unexpected_result;
} else {
std.print(bytes = "Hello from parent\n");
}
} else {
std.print(bytes = "Unable to create child process\n");
return Error.unexpected_result;
}
}