commit 5c0309a9e59413048c97c2fbc7cde5676069c29f (tree)
parent a6d444c2714f24b7232895cf15282e2287fe445e
Author: Giuseppe Cesarano <PecoraInPannaCotta@gmail.com>
Date: Fri, 7 Nov 2025 08:52:35 +0100
std.posix: implemented getpid and getppid
Diffstat:
2 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/lib/std/posix.zig b/lib/std/posix.zig
@@ -1699,6 +1699,14 @@ pub fn dup2(old_fd: fd_t, new_fd: fd_t) !void {
}
}
+pub fn getpid() pid_t {
+ return system.getpid();
+}
+
+pub fn getppid() pid_t {
+ return system.getppid();
+}
+
pub const ExecveError = error{
SystemResources,
AccessDenied,
diff --git a/lib/std/posix/test.zig b/lib/std/posix/test.zig
@@ -621,6 +621,21 @@ test "dup & dup2" {
try testing.expectEqualStrings("dupdup2", try tmp.dir.readFile("os_dup_test", &buffer));
}
+test "getpid" {
+ if (native_os == .wasi) return error.SkipZigTest;
+ if (native_os == .windows) return error.SkipZigTest;
+
+ try expect(posix.getpid() != 0);
+}
+
+test "getppid" {
+ if (native_os == .wasi) return error.SkipZigTest;
+ if (native_os == .windows) return error.SkipZigTest;
+ if (native_os == .plan9 and !builtin.link_libc) return error.SkipZigTest;
+
+ try expect(posix.getppid() >= 0);
+}
+
test "writev longer than IOV_MAX" {
if (native_os == .windows or native_os == .wasi) return error.SkipZigTest;